Skip to content

Commit

Permalink
Merge pull request #1 from moufmouf/unittests
Browse files Browse the repository at this point in the history
Adding unit tests
  • Loading branch information
moufmouf authored Mar 15, 2019
2 parents ce46fe8 + b98f240 commit e9ccca1
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor/
/composer.lock
/build
/cache
56 changes: 56 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
language: php
sudo: false
cache:
directories:
- $HOME/.composer/cache/files
#- $HOME/symfony-bridge/.phpunit

env:
global:
- PHPUNIT_FLAGS="-v"
#- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"

matrix:
fast_finish: true
include:
# Test the latest stable release
- php: 7.1
- php: 7.2
- php: 7.3
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"

# Test LTS versions.
- php: 7.3
env: DEPENDENCIES="symfony/lts:^4"

# Latest commit to master
- php: 7.3
env: STABILITY="dev"

allow_failures:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
# Dev-master is allowed to fail.
- env: STABILITY="dev"

before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

install:
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
#- ./vendor/bin/simple-phpunit install

script:
- composer validate --strict --no-check-lock
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
#- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
- composer phpstan
- ./vendor/bin/phpunit
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/tdbm-bundle/v/stable)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/tdbm-bundle/v/unstable)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
[![License](https://poser.pugx.org/thecodingmachine/tdbm-bundle/license)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
[![Build Status](https://travis-ci.org/thecodingmachine/tdbm-bundle.svg?branch=master)](https://travis-ci.org/thecodingmachine/tdbm-bundle)
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/tdbm-bundle/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/tdbm-bundle?branch=master)

# TDBM Symfony bundle

TDBM integration package for Symfony 4.
Expand Down
27 changes: 27 additions & 0 deletions Tests/Fixtures/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\:
resource: '../*'
exclude: '../{Entities}'

# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
#App\Controller\:
# resource: '../src/Controller'
# tags: ['controller.service_arguments']

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
21 changes: 21 additions & 0 deletions Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace TheCodingMachine\TDBM\Bundle\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use TheCodingMachine\GraphQLite\Schema;
use TheCodingMachine\TDBM\TDBMService;

class FunctionalTest extends TestCase
{
public function testServiceWiring()
{
$kernel = new TdbmTestingKernel('test', true);
$kernel->boot();
$container = $kernel->getContainer();

$tdbmService = $container->get(TDBMService::class);
$this->assertInstanceOf(TDBMService::class, $tdbmService);
}
}
72 changes: 72 additions & 0 deletions Tests/TdbmTestingKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php


namespace TheCodingMachine\TDBM\Bundle\Tests;


use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use TheCodingMachine\Graphqlite\Bundle\GraphqliteBundle;
use TheCodingMachine\TDBM\Bundle\TdbmBundle;
use TheCodingMachine\TDBM\Bundle\TdbmGraphqlBundle;

class TdbmTestingKernel extends Kernel
{
use MicroKernelTrait;

const CONFIG_EXTS = '.{php,xml,yaml,yml}';

public function __construct()
{
parent::__construct('test', true);
}

public function registerBundles()
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new DoctrineBundle(),
new TdbmBundle(),
];
}

public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$loader->load(function(ContainerBuilder $container) {
$container->loadFromExtension('framework', array(
'secret' => 'S0ME_SECRET',
));
$container->loadFromExtension('doctrine', array(
'dbal' => [
'driver' => 'pdo_mysql',
'server_version' => '5.7',
'charset'=> 'utf8mb4',
'default_table_options' => [
'charset' => 'utf8mb4',
'collate' => 'utf8mb4_unicode_ci',
],
'url' => '%env(resolve:DATABASE_URL)%'
]
));
});
$confDir = $this->getProjectDir().'/Tests/Fixtures/config';

$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}

protected function configureRoutes(RouteCollectionBuilder $routes)
{
}

public function getCacheDir()
{
return __DIR__.'/../cache/'.spl_object_hash($this);
}
}
17 changes: 16 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,28 @@
"php" : ">=7.1",
"thecodingmachine/tdbm" : "~5.0.0",
"doctrine/doctrine-bundle": "^1.9",
"doctrine/orm": "*"
"doctrine/orm": "^1 || ^2"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"symfony/security-bundle": "^4.1.9",
"symfony/yaml": "^4.1.9",
"phpunit/phpunit": "^7.5.6",
"phpstan/phpstan": "^0.11.4"
},
"scripts": {
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Resources/ -c phpstan.neon --level=7 --no-progress"
},
"autoload" : {
"psr-4" : {
"TheCodingMachine\\TDBM\\Bundle\\" : ""
}
},
"autoload-dev" : {
"psr-4" : {
"TheCodingMachine\\TDBM\\Bundle\\" : ""
}
},
"extra": {
"branch-alias": {
"dev-master": "5.0.x-dev"
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
ignoreErrors:
- "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)#"
#includes:
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon
39 changes: 39 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Graphql controllers bundle Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
<directory>./var</directory>
</exclude>
</whitelist>
</filter>

<php>
<env name="DATABASE_URL" value="mysql://root:[email protected]:3306/test_tdbmbundle" />
</php>

<logging>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
39 changes: 39 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Graphql controllers bundle Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
<directory>./var</directory>
</exclude>
</whitelist>
</filter>

<php>
<env name="DATABASE_URL" value="mysql://root:@127.0.0.1:3306/test_tdbmbundle" />
</php>

<logging>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>

0 comments on commit e9ccca1

Please sign in to comment.