-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from GaryPEGEOT/feature/sf-42
Feature/sf 42
- Loading branch information
Showing
10 changed files
with
166 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor | ||
composer.lock | ||
.idea | ||
.php_cs.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
@@ -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
19
src/DependencyInjection/MiaouCorpFixtureLoaderExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
@@ -16,7 +21,7 @@ | |
use Symfony\Component\Finder\Finder; | ||
|
||
/** | ||
* Class MiaouCorp\Bundle\FixtureLoaderBundle\FixtureLoader | ||
* Class MiaouCorp\Bundle\FixtureLoaderBundle\FixtureLoader. | ||
* | ||
* @author Gary PEGEOT <[email protected]> | ||
*/ | ||
|
@@ -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 | ||
{ | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
} | ||
|
@@ -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(); | ||
|
||
|
@@ -111,6 +116,5 @@ public function buildSchema() | |
throw new \InvalidArgumentException("Schema is not buildable: {$e->getMessage()}", $e->getCode(), $e); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
@@ -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(); | ||
|
||
|
@@ -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]); | ||
} | ||
} |
Oops, something went wrong.