Skip to content

Commit

Permalink
Merge pull request #1 from GaryPEGEOT/feature/sf-42
Browse files Browse the repository at this point in the history
Feature/sf 42
  • Loading branch information
GaryPEGEOT authored Nov 4, 2018
2 parents 9f495de + e4c9349 commit d524fa5
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
.idea
.php_cs.cache
63 changes: 63 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

$header = <<<OEF
This file is part of the MiaouCorpFixtureLoaderBundle project.
(c) Gary PEGEOT <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
OEF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP56Migration:risky' => true,
// See: https://twitter.com/nicolasgrekas/status/1027125316744081408?s=09
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
'php_unit_internal_class' => true,
'@PHPUnit54Migration:risky' => true,
'@PHPUnit55Migration:risky' => true,
'@PHPUnit56Migration:risky' => true,
'@PHPUnit57Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'@PHP70Migration:risky' => true,
'@PHP71Migration:risky' => true,
'header_comment' => ['header' => $header],
'array_syntax' => ['syntax' => 'short'],
'ordered_class_elements' => true,
'ordered_imports' => true,
'heredoc_to_nowdoc' => true,
'php_unit_strict' => true,
'php_unit_construct' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_order' => true,
'strict_comparison' => true,
'strict_param' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block',
],
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'semicolon_after_instruction' => true,
'combine_consecutive_unsets' => true,
'ternary_to_null_coalescing' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in('src')
->in('tests')
)
;
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ matrix:
# Minimum supported dependencies with the latest and oldest PHP version
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"
- php: 7.0
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak_vendors"

# Test the latest stable release
- php: 7.0
- php: 7.1
- php: 7.2
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"php": ">=7.0.0",
"php": ">=7.1.0",
"nelmio/alice": "^3.2",
"symfony/finder": "~2.8|~3.0|~4.0"
},
Expand Down
19 changes: 13 additions & 6 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the MiaouCorpFixtureLoaderBundle project.
*
* (c) Gary PEGEOT <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MiaouCorp\Bundle\FixtureLoaderBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand All @@ -17,19 +28,15 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('miaoucorp_fixture_loader');
$treeBuilder = new TreeBuilder('miaoucorp_fixture_loader');
$rootNode = \method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('miaoucorp_fixture_loader');
$rootNode->children()
->scalarNode('directory')
->cannotBeEmpty()
->defaultValue('%kernel.project_dir%/tests/Resources/fixtures')
->end()
->end();

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
19 changes: 15 additions & 4 deletions src/DependencyInjection/MiaouCorpFixtureLoaderExtension.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of the MiaouCorpFixtureLoaderBundle project.
*
* (c) Gary PEGEOT <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MiaouCorp\Bundle\FixtureLoaderBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
* @see http://symfony.com/doc/current/cookbook/bundles/extension.html
*/
class MiaouCorpFixtureLoaderExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
Expand Down
28 changes: 16 additions & 12 deletions src/FixtureLoader.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
/**
* This file is part of the FixtureLoaderBundle package.

declare(strict_types=1);

/*
* This file is part of the MiaouCorpFixtureLoaderBundle project.
*
* (c) Gary PEGEOT <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand All @@ -16,7 +21,7 @@
use Symfony\Component\Finder\Finder;

/**
* Class MiaouCorp\Bundle\FixtureLoaderBundle\FixtureLoader
* Class MiaouCorp\Bundle\FixtureLoaderBundle\FixtureLoader.
*
* @author Gary PEGEOT <[email protected]>
*/
Expand Down Expand Up @@ -53,10 +58,11 @@ public function __construct(EntityManagerInterface $em, FileLoaderInterface $loa

/**
* @param string $filename Filename to load
* @param array $keep Fixture(s) name to keep in memory for later use.
* @param array $keep fixture(s) name to keep in memory for later use
*
* @return object[] The generated fixtures matching `$keep` list.
* @throws \InvalidArgumentException
*
* @return object[] the generated fixtures matching `$keep` list
*/
public function loadFile(string $filename, array $keep = []): array
{
Expand All @@ -73,7 +79,7 @@ public function loadFile(string $filename, array $keep = []): array
foreach ($files as $file) {
try {
foreach ($this->loader->loadFile($file->getRealPath())->getObjects() as $id => $object) {
if (\in_array($id, $keep)) {
if (\in_array($id, $keep, true)) {
$fixtures[$id] = $object;
}

Expand All @@ -84,8 +90,7 @@ public function loadFile(string $filename, array $keep = []): array
}
$this->em->flush();
$this->em->clear();

} catch (LoadingThrowable $e) {
} catch (LoadingThrowable | \LogicException $e) {
throw new \InvalidArgumentException("Fixture file \"$file\" isn't loadable: {$e->getMessage()}", $e->getCode(), $e);
}
}
Expand All @@ -94,11 +99,11 @@ public function loadFile(string $filename, array $keep = []): array
}

/**
* Erase and recreate database schema. (All data will be lost!)
* Erase and recreate database schema. (All data will be lost!).
*
* @throws \InvalidArgumentException
*/
public function buildSchema()
public function buildSchema(): void
{
$meta = $this->em->getMetadataFactory()->getAllMetadata();

Expand All @@ -111,6 +116,5 @@ public function buildSchema()
throw new \InvalidArgumentException("Schema is not buildable: {$e->getMessage()}", $e->getCode(), $e);
}
}

}
}
}
11 changes: 11 additions & 0 deletions src/MiaouCorpFixtureLoaderBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the MiaouCorpFixtureLoaderBundle project.
*
* (c) Gary PEGEOT <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MiaouCorp\Bundle\FixtureLoaderBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand Down
18 changes: 13 additions & 5 deletions tests/DependencyInjection/MiaouCorpFixtureLoaderExtensionTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<?php
/**
* This file is part of the FixtureLoaderBundle package.

declare(strict_types=1);

/*
* This file is part of the MiaouCorpFixtureLoaderBundle project.
*
* (c) Gary PEGEOT <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand All @@ -12,11 +17,14 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* @internal
*/
class MiaouCorpFixtureLoaderExtensionTest extends TestCase
{
public function testLoad()
public function testLoad(): void
{
$dir = dirname(__FILE__);
$dir = __DIR__;
$container = new ContainerBuilder();
$ext = new MiaouCorpFixtureLoaderExtension();

Expand All @@ -25,6 +33,6 @@ public function testLoad()
$args = $container->findDefinition('miaoucorp.fixture_loader')->getArguments();

$this->assertCount(3, $args);
$this->assertEquals($dir, $args[2]);
$this->assertSame($dir, $args[2]);
}
}
Loading

0 comments on commit d524fa5

Please sign in to comment.