Skip to content

Commit e9ccca1

Browse files
authored
Merge pull request #1 from moufmouf/unittests
Adding unit tests
2 parents ce46fe8 + b98f240 commit e9ccca1

File tree

10 files changed

+283
-1
lines changed

10 files changed

+283
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/vendor/
22
/composer.lock
3+
/build
4+
/cache

.travis.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
language: php
2+
sudo: false
3+
cache:
4+
directories:
5+
- $HOME/.composer/cache/files
6+
#- $HOME/symfony-bridge/.phpunit
7+
8+
env:
9+
global:
10+
- PHPUNIT_FLAGS="-v"
11+
#- SYMFONY_PHPUNIT_DIR="$HOME/symfony-bridge/.phpunit"
12+
13+
matrix:
14+
fast_finish: true
15+
include:
16+
# Test the latest stable release
17+
- php: 7.1
18+
- php: 7.2
19+
- php: 7.3
20+
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
21+
22+
# Test LTS versions.
23+
- php: 7.3
24+
env: DEPENDENCIES="symfony/lts:^4"
25+
26+
# Latest commit to master
27+
- php: 7.3
28+
env: STABILITY="dev"
29+
30+
allow_failures:
31+
# Minimum supported dependencies with the latest and oldest PHP version
32+
- php: 7.3
33+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
34+
- php: 7.1
35+
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
36+
# Dev-master is allowed to fail.
37+
- env: STABILITY="dev"
38+
39+
before_install:
40+
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
41+
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
42+
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
43+
44+
install:
45+
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
46+
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
47+
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
48+
#- ./vendor/bin/simple-phpunit install
49+
50+
script:
51+
- composer validate --strict --no-check-lock
52+
# simple-phpunit is the PHPUnit wrapper provided by the PHPUnit Bridge component and
53+
# it helps with testing legacy code and deprecations (composer require symfony/phpunit-bridge)
54+
#- ./vendor/bin/simple-phpunit $PHPUNIT_FLAGS
55+
- composer phpstan
56+
- ./vendor/bin/phpunit

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[![Latest Stable Version](https://poser.pugx.org/thecodingmachine/tdbm-bundle/v/stable)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
2+
[![Latest Unstable Version](https://poser.pugx.org/thecodingmachine/tdbm-bundle/v/unstable)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
3+
[![License](https://poser.pugx.org/thecodingmachine/tdbm-bundle/license)](https://packagist.org/packages/thecodingmachine/tdbm-bundle)
4+
[![Build Status](https://travis-ci.org/thecodingmachine/tdbm-bundle.svg?branch=master)](https://travis-ci.org/thecodingmachine/tdbm-bundle)
5+
[![Coverage Status](https://coveralls.io/repos/thecodingmachine/tdbm-bundle/badge.svg?branch=master&service=github)](https://coveralls.io/github/thecodingmachine/tdbm-bundle?branch=master)
6+
17
# TDBM Symfony bundle
28

39
TDBM integration package for Symfony 4.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This file is the entry point to configure your own services.
2+
# Files in the packages/ subdirectory configure your dependencies.
3+
4+
# Put parameters here that don't need to change on each machine where the app is deployed
5+
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
6+
parameters:
7+
8+
services:
9+
# default configuration for services in *this* file
10+
_defaults:
11+
autowire: true # Automatically injects dependencies in your services.
12+
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
13+
14+
# makes classes in src/ available to be used as services
15+
# this creates a service per class whose id is the fully-qualified class name
16+
TheCodingMachine\Graphqlite\Bundle\Tests\Fixtures\:
17+
resource: '../*'
18+
exclude: '../{Entities}'
19+
20+
# controllers are imported separately to make sure services can be injected
21+
# as action arguments even if you don't extend any base controller class
22+
#App\Controller\:
23+
# resource: '../src/Controller'
24+
# tags: ['controller.service_arguments']
25+
26+
# add more service definitions when explicit configuration is needed
27+
# please note that last definitions always *replace* previous ones

Tests/FunctionalTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace TheCodingMachine\TDBM\Bundle\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\HttpFoundation\Request;
7+
use TheCodingMachine\GraphQLite\Schema;
8+
use TheCodingMachine\TDBM\TDBMService;
9+
10+
class FunctionalTest extends TestCase
11+
{
12+
public function testServiceWiring()
13+
{
14+
$kernel = new TdbmTestingKernel('test', true);
15+
$kernel->boot();
16+
$container = $kernel->getContainer();
17+
18+
$tdbmService = $container->get(TDBMService::class);
19+
$this->assertInstanceOf(TDBMService::class, $tdbmService);
20+
}
21+
}

Tests/TdbmTestingKernel.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
4+
namespace TheCodingMachine\TDBM\Bundle\Tests;
5+
6+
7+
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
8+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
9+
use Symfony\Component\Config\Loader\LoaderInterface;
10+
use Symfony\Component\DependencyInjection\ContainerBuilder;
11+
use Symfony\Component\HttpKernel\Kernel;
12+
use Symfony\Component\Routing\RouteCollectionBuilder;
13+
use TheCodingMachine\Graphqlite\Bundle\GraphqliteBundle;
14+
use TheCodingMachine\TDBM\Bundle\TdbmBundle;
15+
use TheCodingMachine\TDBM\Bundle\TdbmGraphqlBundle;
16+
17+
class TdbmTestingKernel extends Kernel
18+
{
19+
use MicroKernelTrait;
20+
21+
const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22+
23+
public function __construct()
24+
{
25+
parent::__construct('test', true);
26+
}
27+
28+
public function registerBundles()
29+
{
30+
return [
31+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
32+
new DoctrineBundle(),
33+
new TdbmBundle(),
34+
];
35+
}
36+
37+
public function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
38+
{
39+
$loader->load(function(ContainerBuilder $container) {
40+
$container->loadFromExtension('framework', array(
41+
'secret' => 'S0ME_SECRET',
42+
));
43+
$container->loadFromExtension('doctrine', array(
44+
'dbal' => [
45+
'driver' => 'pdo_mysql',
46+
'server_version' => '5.7',
47+
'charset'=> 'utf8mb4',
48+
'default_table_options' => [
49+
'charset' => 'utf8mb4',
50+
'collate' => 'utf8mb4_unicode_ci',
51+
],
52+
'url' => '%env(resolve:DATABASE_URL)%'
53+
]
54+
));
55+
});
56+
$confDir = $this->getProjectDir().'/Tests/Fixtures/config';
57+
58+
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
59+
$loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
60+
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
61+
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
62+
}
63+
64+
protected function configureRoutes(RouteCollectionBuilder $routes)
65+
{
66+
}
67+
68+
public function getCacheDir()
69+
{
70+
return __DIR__.'/../cache/'.spl_object_hash($this);
71+
}
72+
}

composer.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,28 @@
2424
"php" : ">=7.1",
2525
"thecodingmachine/tdbm" : "~5.0.0",
2626
"doctrine/doctrine-bundle": "^1.9",
27-
"doctrine/orm": "*"
27+
"doctrine/orm": "^1 || ^2"
28+
},
29+
"require-dev": {
30+
"roave/security-advisories": "dev-master",
31+
"symfony/security-bundle": "^4.1.9",
32+
"symfony/yaml": "^4.1.9",
33+
"phpunit/phpunit": "^7.5.6",
34+
"phpstan/phpstan": "^0.11.4"
35+
},
36+
"scripts": {
37+
"phpstan": "phpstan analyse TdbmBundle.php DependencyInjection/ Resources/ -c phpstan.neon --level=7 --no-progress"
2838
},
2939
"autoload" : {
3040
"psr-4" : {
3141
"TheCodingMachine\\TDBM\\Bundle\\" : ""
3242
}
3343
},
44+
"autoload-dev" : {
45+
"psr-4" : {
46+
"TheCodingMachine\\TDBM\\Bundle\\" : ""
47+
}
48+
},
3449
"extra": {
3550
"branch-alias": {
3651
"dev-master": "5.0.x-dev"

phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
parameters:
2+
ignoreErrors:
3+
- "#Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition::children\\(\\)#"
4+
#includes:
5+
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

phpunit.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
bootstrap="vendor/autoload.php"
12+
>
13+
<testsuites>
14+
<testsuite name="Graphql controllers bundle Test Suite">
15+
<directory>./Tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory>./</directory>
22+
<exclude>
23+
<directory>./Resources</directory>
24+
<directory>./Tests</directory>
25+
<directory>./vendor</directory>
26+
<directory>./var</directory>
27+
</exclude>
28+
</whitelist>
29+
</filter>
30+
31+
<php>
32+
<env name="DATABASE_URL" value="mysql://root:admin@127.0.0.1:3306/test_tdbmbundle" />
33+
</php>
34+
35+
<logging>
36+
<log type="coverage-html" target="build/coverage"/>
37+
<log type="coverage-clover" target="build/logs/clover.xml"/>
38+
</logging>
39+
</phpunit>

phpunit.xml.dist

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
bootstrap="vendor/autoload.php"
12+
>
13+
<testsuites>
14+
<testsuite name="Graphql controllers bundle Test Suite">
15+
<directory>./Tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
<filter>
20+
<whitelist>
21+
<directory>./</directory>
22+
<exclude>
23+
<directory>./Resources</directory>
24+
<directory>./Tests</directory>
25+
<directory>./vendor</directory>
26+
<directory>./var</directory>
27+
</exclude>
28+
</whitelist>
29+
</filter>
30+
31+
<php>
32+
<env name="DATABASE_URL" value="mysql://root:@127.0.0.1:3306/test_tdbmbundle" />
33+
</php>
34+
35+
<logging>
36+
<log type="coverage-html" target="build/coverage"/>
37+
<log type="coverage-clover" target="build/logs/clover.xml"/>
38+
</logging>
39+
</phpunit>

0 commit comments

Comments
 (0)