pax_global_header00006660000000000000000000000064136123041620014510gustar00rootroot0000000000000052 comment=bbdaa7ab8cf711e288c3b2b49be9806d05508b1d php-doctrine-data-fixtures-1.4.2/000077500000000000000000000000001361230416200166665ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/.doctrine-project.json000066400000000000000000000010061361230416200231070ustar00rootroot00000000000000{ "active": true, "name": "Data fixtures", "slug": "data-fixtures", "docsSlug": "doctrine-data-fixtures", "versions": [ { "name": "1.4", "branchName": "master", "slug": "latest", "upcoming": true }, { "name": "1.3", "branchName": "1.3", "slug": "1.3", "current": true, "aliases": [ "current", "stable" ] } ] } php-doctrine-data-fixtures-1.4.2/.github/000077500000000000000000000000001361230416200202265ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/.github/FUNDING.yml000066400000000000000000000001741361230416200220450ustar00rootroot00000000000000patreon: phpdoctrine tidelift: packagist/doctrine%2Fdata-fixtures custom: https://www.doctrine-project.org/sponsorship.html php-doctrine-data-fixtures-1.4.2/.gitignore000066400000000000000000000000571361230416200206600ustar00rootroot00000000000000phpunit.xml vendor/ .phpcs-cache composer.lock php-doctrine-data-fixtures-1.4.2/.travis.yml000066400000000000000000000010661361230416200210020ustar00rootroot00000000000000language: php sudo: false cache: directories: - $HOME/.composer/cache php: - 7.2 - 7.3 - 7.4snapshot services: mongodb before_install: - pecl install -f mongodb - composer validate --strict install: - composer update --prefer-stable --prefer-dist ${COMPOSER_FLAGS} script: - ./vendor/bin/phpunit -v jobs: include: # Tests the lowest set of dependencies - php: 7.2 env: LOWEST COMPOSER_FLAGS="--prefer-lowest" - stage: Code Quality env: CODING_STANDARDS php: 7.2 script: - ./vendor/bin/phpcs php-doctrine-data-fixtures-1.4.2/CHANGELOG.md000066400000000000000000000312341361230416200205020ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [1.3.0] - 2017-11-27 ### Fixed - [248: Rename example classes names for consistency](https://github.com/doctrine/data-fixtures/pull/248) - @Kwadz - [253: Fix syntax highlighting on README](https://github.com/doctrine/data-fixtures/pull/253) - @fefas - [269: Remove tabs](https://github.com/doctrine/data-fixtures/pull/269) - @garak ### Changed - [266: Bump PHP requirement to 7.1](https://github.com/doctrine/data-fixtures/pull/266) - @alcaeus ### Added - [255: Added handling of PHPCR documents on method `getIdentifier()`](https://github.com/doctrine/data-fixtures/pull/255) - @aemaething - [274: Hook point to control creating fixtures objects](https://github.com/doctrine/data-fixtures/pull/274) - @weaverryan ### Fixed - [572: Only show generated migration in verbose mode](https://github.com/doctrine/migrations/pull/572) - @alcaeus ## [1.6.0] - 2017-11-09 ### Fixed - [536: Fix typo in exception message](https://github.com/doctrine/migrations/pull/536) - @mantiz - [545: Allow nullable custom template](https://github.com/doctrine/migrations/pull/545) - @PapsOu - [560: Fix `--dry-run` and `--write-sql` with `addSql`](https://github.com/doctrine/migrations/pull/560) - @mikeSimonson - [569: Allow using absolute paths for custom template](https://github.com/doctrine/migrations/pull/569) - @alcaeus ### Changed - [537: Require PHP 7.1](https://github.com/doctrine/migrations/pull/537) - @lcobucci - [563: Remove copyright headers](https://github.com/doctrine/migrations/pull/563) - @mikeSimonson - [534: Change RecursiveRegexFinder to follow Symlinks](https://github.com/doctrine/migrations/pull/534) - @burci ### Added - [506: Add migration events](https://github.com/doctrine/migrations/pull/506) - @chrisguitarguy - [509: Add delta in migrate command](https://github.com/doctrine/migrations/pull/509) - @Safranil - [535: Allow changing migration class template in generate command](https://github.com/doctrine/migrations/pull/535) - @PapsOu - [542: Enable phpcs to ensure coding style](https://github.com/doctrine/migrations/pull/542) - @lcobucci - [562: Allow providing a path for file dump](https://github.com/doctrine/migrations/pull/562) - @mikeSimonson - [565: Allow Symfony 4](https://github.com/doctrine/migrations/565) - @weaverryan - [568: Add `ConfigurationHelperInterface` to allow overriding internal class](https://github.com/doctrine/migrations/pull/568) - @alcaeus - [571: Allow changing migration class template in diff command](https://github.com/doctrine/migrations/pull/571) - @alcaeus ## [1.5.0] - 2016-12-25 ### Fixed - [447: Fix typo in error code](https://github.com/doctrine/migrations/pull/447) thanks to @funivan - [448: Removed unused import](https://github.com/doctrine/migrations/pull/448) thanks to @localheinz - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz - [449: Use the class keyword](https://github.com/doctrine/migrations/pull/449) thanks to @localheinz - [453: Use better assertions](https://github.com/doctrine/migrations/pull/453) thanks to @localheinz - [452: Fix the visibility of the AbstractTest](https://github.com/doctrine/migrations/pull/452) thanks to @localheinz - [450: Use the short array syntax](https://github.com/doctrine/migrations/pull/450) thanks to @localheinz - [464: Clean the github autogenerated zip archive](https://github.com/doctrine/migrations/pull/464) thanks to @mlocati - [457: Fix an issue where the migration wheren't sorted propely](https://github.com/doctrine/migrations/pull/457) thanks to @JHGitty, @Charles68 - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz - [471: Fix loading the configuration from a php file](https://github.com/doctrine/migrations/pull/471) thanks to @aaa2000 - [451: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/451) thanks to @localheinz - [472: Change comment marker a cross platform one ](https://github.com/doctrine/migrations/pull/472) thanks to @aaa2000 - [476: Add test for the execute command](https://github.com/doctrine/migrations/pull/476) thanks to @chrisguitarguy - [470: Case insensitive method calls and types](https://github.com/doctrine/migrations/pull/470) thanks to @abacaphiliac - [489: Better help message in the execute command](https://github.com/doctrine/migrations/pull/489) thanks to @eko - [500: Updating the dev dependencies](https://github.com/doctrine/migrations/pull/500) thanks to @mikeSimonson - [501: Fix a bug in a rarely used message call](https://github.com/doctrine/migrations/pull/501) thanks to @Seldaek ### Changed - [478: Changed the default generated version number to UTC](https://github.com/doctrine/migrations/pull/446) thanks to @c960657 - [479: Explicitly connecting to support master slave connections](https://github.com/doctrine/migrations/pull/479) thanks to @chrisguitarguy - [482: Use strict comparaison in the generated migrations](https://github.com/doctrine/migrations/pull/482) thanks to @tifabien ### Added - [470: Add uptodate command](https://github.com/doctrine/migrations/pull/470) thanks to @abacaphiliac - [477: Add parameters to the output of the dry run migrations](https://github.com/doctrine/migrations/pull/477) thanks to @chrisguitarguy - [497: Show the content of the generated file on the console](https://github.com/doctrine/migrations/pull/497) thanks to @ErikTrapman - [480: Don't prompt the user for confirmation when there is nothing to do](https://github.com/doctrine/migrations/pull/480) thanks to @chrisguitarguy ## [1.4.1] - 2016-03-14 ### Fixed - [439: Add missing dependency in the phar build](https://github.com/doctrine/migrations/pull/439) ## [1.4.0] - 2016-02-23 ### Added - [431: Formatted diffs](https://github.com/doctrine/migrations/pull/431) - [437: Allowing to set the column name from config too](https://github.com/doctrine/migrations/pull/437) ## [1.3.1] - 2016-02-23 ### Fixed - [433: Fix: ExecuteCommand by making sure that it autoload the versions](https://github.com/doctrine/migrations/pull/433) - [434: Fixing an issue in the order at which some configuration key are loaded](https://github.com/doctrine/migrations/pull/434) ### Changed - [429: code refactoring for clarity](https://github.com/doctrine/migrations/pull/429) - [428: code refactoring for clarity](https://github.com/doctrine/migrations/pull/428) ### Added - [425: ProxyManager ~2.0 is also compatible with migrations](https://github.com/doctrine/migrations/pull/425) ## [1.3.0] - 2016-01-23 ### Fixed - [421: Fix issue with some method when the migrations were not loaded](https://github.com/doctrine/migrations/pull/421) - [405: Correcting composer constraints: allowing PHP 7, dropping 5.4 support](https://github.com/doctrine/migrations/pull/405) - [406: putting the composer.json back in the archive](https://github.com/doctrine/migrations/pull/406) ### Changed - [233: Separate Configuration Objects from Configuration File Loading](https://github.com/doctrine/migrations/issues/233) - [407: Replacing the Schema by a proxy](https://github.com/doctrine/migrations/pull/407) - [422: Refactor the getConnection into a chainloader](https://github.com/doctrine/migrations/pull/422) - [Dropped the support for php 5.4](https://github.com/doctrine/migrations/pull/393) - [Again make the phar more than 3 times smaller](https://github.com/doctrine/migrations/pull/396) ### Added - [404: add possibility to read doctrine's config/cli-config.php](https://github.com/doctrine/migrations/pull/404) - [409: Add a failing test case for an edge case with the write-sql option](https://github.com/doctrine/migrations/pull/409) - [424: Adding a regression test for the configuration](https://github.com/doctrine/migrations/pull/424) - [391: Give the possibility to override the Migration template](https://github.com/doctrine/migrations/pull/391) ## [1.2.2] - 2016-01-07 ### Fixed - [Fix the write-sql option in the version class too](https://github.com/doctrine/migrations/commit/91043f742da8506ab7115a1d14247ce26375f6f5) ## [1.2.1] - 2015-12-23 ### Fixed - [Fix the write-sql option](https://github.com/doctrine/migrations/pull/400) ## [1.2.0] - 2015-12-15 ### Fixed - [fix "all migrated versions shown as unavailable executed" ](https://github.com/doctrine/migrations/commit/875849e2a80d37dc8bf5dd0663e464b6789e3b56) - [Prevent the use of 0 as migration name as it is used internally and conflict](http://github.com/doctrine/migrations/commit/5df49c5ad5dc2265401a54a3b9e6ecb3e7cda8d0) - [composer: drop symfony/console from suggested packages, since it's required package](http://github.com/doctrine/migrations/commit/d263c7bfac7188009ab0717ed5aa6577e80) - [fix spaces and complete missing file-docblocks](http://github.com/doctrine/migrations/commit/4b68a69c3e35492b36ec140ebb216cdb80ffe655) - [RecursiveDirectoryIterator don't obtain some order of the file list.](http://github.com/doctrine/migrations/commit/ed95c05c14381e64404f1135763fcc9b65317b96) - [Fix the yml parser issue with unescaped backslash in double quoted string](http://github.com/doctrine/migrations/commit/af3cce7d2e490ead821fcbdb54b4772b4913ee1d) ### Changed - [Adding compression to the generation of the phar](http://github.com/doctrine/migrations/commit/70730ff8655f0be89ce0f06d1e279930d7eb2550) - [tests: move autoload of tests to composer](http://github.com/doctrine/migrations/commit/3a4f8368e4b7b95d2e6c51c26f6dc41bb05a5ce5) - [travis: drop PHP 7.0 from allowed failures, it passes well](http://github.com/doctrine/migrations/commit/57ec2f071a7a840c554058b77f2089893d06ba23) - [Revert the use of exec to run sql queries](http://github.com/doctrine/migrations/commit/0af6e6e705b905a56cbed26cb5c17faad4c2c04f) ### Added - [Adding a little script to prepare and generate the phar](http://github.com/doctrine/migrations/commit/3a8ef413e7f8a42d4e0f3d32d30601b26fb27e60) - [Configuration: check if migration class exists added](http://github.com/doctrine/migrations/commit/a53d7c83b319341c985d2a21950e260fa55b0b8d) - [Made composer.json compatible with SF 3.0](http://github.com/doctrine/migrations/commit/4e909f2e661a8414a3e04ce987a09c9e849cd13f) - [Added configurable version column name](http://github.com/doctrine/migrations/commit/02ddf4318b84a20bb0e3486acfc6e6f41cc63426) ## [1.1.0] - 2015-09-29 ### Fixed - [Switch unexisting tag to ](http://github.com/doctrine/migrations/commit/93a81ff0dcc858de4df5c17d97f2f24b3bfa3c36) - [Ensure that Yaml::parse return an array as it can apparently return a string](http://github.com/doctrine/migrations/commit/1499f0cc3e5f5b20a510ba8f0779d5c68a9e5084) - [Avoid uploading code coverage to Scrutinizer for HHVM and PHP 7](http://github.com/doctrine/migrations/commit/d47d65021dcb711480bf27f6d0bbba138e220f12) - [Improve the Travis configuration by persisting the composer cache](http://github.com/doctrine/migrations/commit/bda0509b479ae6605b8fa749b0999b4ce2ff8c04) - [Keep the license file in the downloadable archives](https://github.com/doctrine/migrations/commit/dfbee38e004899bc078d5d47b13bea53799fca1e#diff-fc723d30b02a4cca7a534518111c1a66) ### Changed - [Use short array syntax](http://github.com/doctrine/migrations/commit/50a6e18c95ff617325229a4a649d65c1a11445bc) - [composer: use PSR-4 autoload](http://github.com/doctrine/migrations/commit/7fb8d301b2f4d4a564433165e0604b7d34013844) - [refactoring the configuration loading](http://github.com/doctrine/migrations/commit/e95b277111c74cfe65eb959d4471f45a815e1ece) - [Drop support for php 5.3](https://github.com/doctrine/migrations/commit/0e60856a10e8b510daa612fe25f6245aece77e68) - [compressing the phar so that it's half the size now](https://github.com/doctrine/migrations/commit/70730ff8655f0be89ce0f06d1e279930d7eb2550) ### Added - [Added the ability to auto create migrations in a folder by month and year](http://github.com/doctrine/migrations/commit/0b8e40868e12a36de7f689add61857b9ba29c4bc) - [Set default name for configuration helper](http://github.com/doctrine/migrations/commit/1f3592f2f126a022db275192f17b8d5c01f19822) - [Added ability to load config from php array or json files.](http://github.com/doctrine/migrations/commit/8cf01d623f9eb3728ba86c22970347107a8f0be7) - [Added the possibility to inject the OutputWriter after instantiation](https://github.com/doctrine/migrations/pull/342) - [Added the --allow-no-migration option to avoid throwing an exception if no migrations are found](https://github.com/doctrine/migrations/commit/a9ec86faa3a3f7f592a633af43b6ef6c9f358239#diff-0a4648a19ba565cda76b349e89552a9b) php-doctrine-data-fixtures-1.4.2/LICENSE000066400000000000000000000020521361230416200176720ustar00rootroot00000000000000Copyright (c) 2006-2015 Doctrine Project Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. php-doctrine-data-fixtures-1.4.2/README.md000066400000000000000000000117231361230416200201510ustar00rootroot00000000000000# Doctrine Data Fixtures Extension [![Build Status](https://travis-ci.org/doctrine/data-fixtures.svg?branch=master)](https://travis-ci.org/doctrine/data-fixtures) This extension aims to provide a simple way to manage and execute the loading of data fixtures for the [Doctrine ORM or ODM](http://www.doctrine-project.org/). You can write fixture classes by implementing the [`Doctrine\Common\DataFixtures\FixtureInterface`](lib/Doctrine/Common/DataFixtures/FixtureInterface.php) interface: ```php namespace MyDataFixtures; use Doctrine\Common\DataFixtures\FixtureInterface; use Doctrine\Persistence\ObjectManager; class UserFixtureLoader implements FixtureInterface { public function load(ObjectManager $manager) { $user = new User(); $user->setUsername('jwage'); $user->setPassword('test'); $manager->persist($user); $manager->flush(); } } ``` Now you can begin adding the fixtures to a loader instance: ```php use Doctrine\Common\DataFixtures\Loader; use MyDataFixtures\UserDataLoader; $loader = new Loader(); $loader->addFixture(new UserDataLoader()); ``` You can load a set of fixtures from a directory as well: ```php $loader->loadFromDirectory('/path/to/MyDataFixtures'); ``` Or you can load a set of fixtures from a file: ```php $loader->loadFromFile('/path/to/MyDataFixtures/MyFixture1.php'); ``` You can get the added fixtures using the getFixtures() method: ```php $fixtures = $loader->getFixtures(); ``` Now you can easily execute the fixtures: ```php use Doctrine\Common\DataFixtures\Executor\ORMExecutor; use Doctrine\Common\DataFixtures\Purger\ORMPurger; $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $executor->execute($loader->getFixtures()); ``` If you want to append the fixtures instead of purging before loading then pass true to the 2nd argument of execute: ```php $executor->execute($loader->getFixtures(), true); ``` ## Sharing objects between fixtures In case if fixture objects have relations to other fixtures, it is now possible to easily add a reference to that object by name and later reference it to form a relation. Here is an example fixtures for **Role** and **User** relation ```php namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Persistence\ObjectManager; class UserRoleDataLoader extends AbstractFixture { public function load(ObjectManager $manager) { $adminRole = new Role(); $adminRole->setName('admin'); $anonymousRole = new Role(); $anonymousRole->setName('anonymous'); $manager->persist($adminRole); $manager->persist($anonymousRole); $manager->flush(); // store reference to admin role for User relation to Role $this->addReference('admin-role', $adminRole); } } ``` And the **User** data loading fixture: ```php namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Persistence\ObjectManager; class UserDataLoader extends AbstractFixture { public function load(ObjectManager $manager) { $user = new User(); $user->setUsername('jwage'); $user->setPassword('test'); $user->setRole( $this->getReference('admin-role') // load the stored reference ); $manager->persist($user); $manager->flush(); // store reference of admin-user for other Fixtures $this->addReference('admin-user', $user); } } ``` ## Fixture ordering **Notice** that the fixture loading order is important! To handle it manually implement one of the following interfaces: ### OrderedFixtureInterface Set the order manually: ```php namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Persistence\ObjectManager; class MyFixture extends AbstractFixture implements OrderedFixtureInterface { public function load(ObjectManager $manager) {} public function getOrder() { return 10; // number in which order to load fixtures } } ``` ### DependentFixtureInterface Provide an array of fixture class names: ```php namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Doctrine\Persistence\ObjectManager; class MyFixture extends AbstractFixture implements DependentFixtureInterface { public function load(ObjectManager $manager) {} public function getDependencies() { return array('MyDataFixtures\MyOtherFixture'); // fixture classes fixture is dependent on } } class MyOtherFixture extends AbstractFixture { public function load(ObjectManager $manager) {} } ``` **Notice** the ordering is relevant to Loader class. ## Running the tests: Phpunit is included in the dev requirements of this package. To setup and run tests follow these steps: - go to the root directory of data-fixtures - run: **composer install --dev** - run: **vendor/bin/phpunit** php-doctrine-data-fixtures-1.4.2/UPGRADE000066400000000000000000000004371361230416200177040ustar00rootroot00000000000000# Between v1.0.0-ALPHA1 and v1.0.0-ALPHA2 The FixtureInterface was changed from interface FixtureInterface { load($manager); } to use Doctrine\Common\Persistence\ObjectManager; interface FixtureInterface { load(ObjectManager $manager); } php-doctrine-data-fixtures-1.4.2/composer.json000066400000000000000000000030411361230416200214060ustar00rootroot00000000000000{ "name": "doctrine/data-fixtures", "type": "library", "description": "Data Fixtures for all Doctrine Object Managers", "keywords": [ "database" ], "homepage": "http://www.doctrine-project.org", "license": "MIT", "authors": [ { "name": "Jonathan Wage", "email": "jonwage@gmail.com" } ], "require": { "php": "^7.2", "doctrine/common": "^2.11", "doctrine/persistence": "^1.3.3" }, "conflict": { "doctrine/phpcr-odm": "<1.3.0" }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", "doctrine/coding-standard": "^6.0", "doctrine/dbal": "^2.5.4", "doctrine/mongodb-odm": "^1.3.0", "doctrine/orm": "^2.7.0", "phpunit/phpunit": "^7.0" }, "suggest": { "alcaeus/mongo-php-adapter": "For using MongoDB ODM with PHP 7", "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", "doctrine/orm": "For loading ORM fixtures", "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" }, "config": { "platform": { "ext-mongo": "1.6.16" }, "sort-packages": true }, "extra": { "branch-alias": { "dev-master": "1.4.x-dev" } }, "autoload": { "psr-4": { "Doctrine\\Common\\DataFixtures\\": "lib/Doctrine/Common/DataFixtures" } }, "autoload-dev": { "psr-4": { "Doctrine\\Tests\\": "tests/Doctrine/Tests" } } } php-doctrine-data-fixtures-1.4.2/lib/000077500000000000000000000000001361230416200174345ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/000077500000000000000000000000001361230416200212035ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/000077500000000000000000000000001361230416200224335ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/000077500000000000000000000000001361230416200250365ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/AbstractFixture.php000066400000000000000000000045461361230416200306720ustar00rootroot00000000000000referenceRepository = $referenceRepository; } /** * Set the reference entry identified by $name * and referenced to managed $object. If $name * already is set, it overrides it * * @see Doctrine\Common\DataFixtures\ReferenceRepository::setReference * * @param string $name * @param object $object - managed object * * @return void */ public function setReference($name, $object) { $this->referenceRepository->setReference($name, $object); } /** * Set the reference entry identified by $name * and referenced to managed $object. If $name * already is set, it throws a * BadMethodCallException exception * * @see Doctrine\Common\DataFixtures\ReferenceRepository::addReference * * @param string $name * @param object $object - managed object * * @return void * * @throws BadMethodCallException - if repository already has a reference by $name. */ public function addReference($name, $object) { $this->referenceRepository->addReference($name, $object); } /** * Loads an object using stored reference * named by $name * * @see Doctrine\Common\DataFixtures\ReferenceRepository::getReference * * @param string $name * * @return object */ public function getReference($name) { return $this->referenceRepository->getReference($name); } /** * Check if an object is stored using reference * named by $name * * @see Doctrine\Common\DataFixtures\ReferenceRepository::hasReference * * @param string $name * * @return bool */ public function hasReference($name) { return $this->referenceRepository->hasReference($name); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php000066400000000000000000000006441361230416200326510ustar00rootroot00000000000000referenceRepository = $referenceRepository; } /** * {@inheritdoc} */ public function getSubscribedEvents() { return ['postPersist']; } /** * Populates identities for stored references */ public function postPersist(LifecycleEventArgs $args) { $object = $args->getDocument(); $names = $this->referenceRepository->getReferenceNames($object); if ($names === false) { return; } foreach ($names as $name) { $identity = $args->getDocumentManager() ->getUnitOfWork() ->getDocumentIdentifier($object); $this->referenceRepository->setReferenceIdentity($name, $identity); } } } ORMReferenceListener.php000066400000000000000000000025611361230416200343240ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Event/ListenerreferenceRepository = $referenceRepository; } /** * {@inheritdoc} */ public function getSubscribedEvents() { // would be better to use onClear, but it is supported only in 2.1 return ['postPersist']; } /** * Populates identities for stored references */ public function postPersist(LifecycleEventArgs $args) { $object = $args->getEntity(); $names = $this->referenceRepository->getReferenceNames($object); if ($names === false) { return; } foreach ($names as $name) { $identity = $args->getEntityManager() ->getUnitOfWork() ->getEntityIdentifier($object); $this->referenceRepository->setReferenceIdentity($name, $identity); } } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Exception/000077500000000000000000000000001361230416200267745ustar00rootroot00000000000000CircularReferenceException.php000066400000000000000000000002671361230416200346750ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/ExceptionreferenceRepository = new ReferenceRepository($manager); } /** * @return ReferenceRepository */ public function getReferenceRepository() { return $this->referenceRepository; } public function setReferenceRepository(ReferenceRepository $referenceRepository) { $this->referenceRepository = $referenceRepository; } /** * Sets the Purger instance to use for this executor instance. */ public function setPurger(PurgerInterface $purger) { $this->purger = $purger; } /** * @return PurgerInterface */ public function getPurger() { return $this->purger; } /** * Set the logger callable to execute with the log() method. * * @param callable $logger */ public function setLogger($logger) { $this->logger = $logger; } /** * Logs a message using the logger. * * @param string $message */ public function log($message) { $logger = $this->logger; $logger($message); } /** * Load a fixture with the given persistence manager. */ public function load(ObjectManager $manager, FixtureInterface $fixture) { if ($this->logger) { $prefix = ''; if ($fixture instanceof OrderedFixtureInterface) { $prefix = sprintf('[%d] ', $fixture->getOrder()); } $this->log('loading ' . $prefix . get_class($fixture)); } // additionally pass the instance of reference repository to shared fixtures if ($fixture instanceof SharedFixtureInterface) { $fixture->setReferenceRepository($this->referenceRepository); } $fixture->load($manager); $manager->clear(); } /** * Purges the database before loading. * * @throws Exception if the purger is not defined. */ public function purge() { if ($this->purger === null) { throw new Exception('Doctrine\Common\DataFixtures\Purger\PurgerInterface instance is required if you want to purge the database before loading your data fixtures.'); } if ($this->logger) { $this->log('purging database'); } $this->purger->purge(); } /** * Executes the given array of data fixtures. * * @param array $fixtures Array of fixtures to execute. * @param bool $append Whether to append the data fixtures or purge the database before loading. */ abstract public function execute(array $fixtures, $append = false); } interface_exists(ObjectManager::class); php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Executor/MongoDBExecutor.php000066400000000000000000000037021361230416200323530ustar00rootroot00000000000000dm = $dm; if ($purger !== null) { $this->purger = $purger; $this->purger->setDocumentManager($dm); } parent::__construct($dm); $this->listener = new MongoDBReferenceListener($this->referenceRepository); $dm->getEventManager()->addEventSubscriber($this->listener); } /** * Retrieve the DocumentManager instance this executor instance is using. * * @return DocumentManager */ public function getObjectManager() { return $this->dm; } /** @inheritDoc */ public function setReferenceRepository(ReferenceRepository $referenceRepository) { $this->dm->getEventManager()->removeEventListener( $this->listener->getSubscribedEvents(), $this->listener ); $this->referenceRepository = $referenceRepository; $this->listener = new MongoDBReferenceListener($this->referenceRepository); $this->dm->getEventManager()->addEventSubscriber($this->listener); } /** @inheritDoc */ public function execute(array $fixtures, $append = false) { if ($append === false) { $this->purge(); } foreach ($fixtures as $fixture) { $this->load($this->dm, $fixture); } } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Executor/ORMExecutor.php000066400000000000000000000042701361230416200315240ustar00rootroot00000000000000em = $em; if ($purger !== null) { $this->purger = $purger; $this->purger->setEntityManager($em); } parent::__construct($em); $this->listener = new ORMReferenceListener($this->referenceRepository); $em->getEventManager()->addEventSubscriber($this->listener); } /** * Retrieve the EntityManagerInterface instance this executor instance is using. * * @return EntityManagerInterface */ public function getObjectManager() { return $this->em; } /** @inheritDoc */ public function setReferenceRepository(ReferenceRepository $referenceRepository) { $this->em->getEventManager()->removeEventListener( $this->listener->getSubscribedEvents(), $this->listener ); $this->referenceRepository = $referenceRepository; $this->listener = new ORMReferenceListener($this->referenceRepository); $this->em->getEventManager()->addEventSubscriber($this->listener); } /** @inheritDoc */ public function execute(array $fixtures, $append = false) { $executor = $this; $this->em->transactional(static function (EntityManagerInterface $em) use ($executor, $fixtures, $append) { if ($append === false) { $executor->purge(); } foreach ($fixtures as $fixture) { $executor->load($em, $fixture); } }); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Executor/PHPCRExecutor.php000066400000000000000000000027741361230416200317520ustar00rootroot00000000000000dm = $dm; if ($purger === null) { return; } $purger->setDocumentManager($dm); $this->setPurger($purger); } public function getObjectManager() { return $this->dm; } /** @inheritDoc */ public function execute(array $fixtures, $append = false) { $that = $this; $function = static function ($dm) use ($append, $that, $fixtures) { if ($append === false) { $that->purge(); } foreach ($fixtures as $fixture) { $that->load($dm, $fixture); } }; if (method_exists($this->dm, 'transactional')) { $this->dm->transactional($function); } else { $function($this->dm); } } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/FixtureInterface.php000066400000000000000000000006241361230416200310200ustar00rootroot00000000000000loadFromIterator($iterator); } /** * Find fixtures classes in a given file and load them. * * @param string $fileName File to find fixture classes in. * * @return array $fixtures Array of loaded fixture object instances. */ public function loadFromFile($fileName) { if (! is_readable($fileName)) { throw new InvalidArgumentException(sprintf('"%s" does not exist or is not readable', $fileName)); } $iterator = new ArrayIterator([new SplFileInfo($fileName)]); return $this->loadFromIterator($iterator); } /** * Has fixture? * * @param FixtureInterface $fixture * * @return bool */ public function hasFixture($fixture) { return isset($this->fixtures[get_class($fixture)]); } /** * Get a specific fixture instance * * @param string $className * * @return FixtureInterface */ public function getFixture($className) { if (! isset($this->fixtures[$className])) { throw new InvalidArgumentException(sprintf( '"%s" is not a registered fixture', $className )); } return $this->fixtures[$className]; } /** * Add a fixture object instance to the loader. */ public function addFixture(FixtureInterface $fixture) { $fixtureClass = get_class($fixture); if (isset($this->fixtures[$fixtureClass])) { return; } if ($fixture instanceof OrderedFixtureInterface && $fixture instanceof DependentFixtureInterface) { throw new InvalidArgumentException(sprintf( 'Class "%s" can\'t implement "%s" and "%s" at the same time.', get_class($fixture), 'OrderedFixtureInterface', 'DependentFixtureInterface' )); } $this->fixtures[$fixtureClass] = $fixture; if ($fixture instanceof OrderedFixtureInterface) { $this->orderFixturesByNumber = true; } elseif ($fixture instanceof DependentFixtureInterface) { $this->orderFixturesByDependencies = true; foreach ($fixture->getDependencies() as $class) { if (! class_exists($class)) { continue; } $this->addFixture($this->createFixture($class)); } } } /** * Returns the array of data fixtures to execute. * * @return array $fixtures */ public function getFixtures() { $this->orderedFixtures = []; if ($this->orderFixturesByNumber) { $this->orderFixturesByNumber(); } if ($this->orderFixturesByDependencies) { $this->orderFixturesByDependencies(); } if (! $this->orderFixturesByNumber && ! $this->orderFixturesByDependencies) { $this->orderedFixtures = $this->fixtures; } return $this->orderedFixtures; } /** * Check if a given fixture is transient and should not be considered a data fixtures * class. * * @return bool */ public function isTransient($className) { $rc = new ReflectionClass($className); if ($rc->isAbstract()) { return true; } $interfaces = class_implements($className); return ! in_array(FixtureInterface::class, $interfaces); } /** * Creates the fixture object from the class. * * @param string $class * * @return FixtureInterface */ protected function createFixture($class) { return new $class(); } /** * Orders fixtures by number * * @return void * * @todo maybe there is a better way to handle reordering */ private function orderFixturesByNumber() { $this->orderedFixtures = $this->fixtures; usort($this->orderedFixtures, static function ($a, $b) { if ($a instanceof OrderedFixtureInterface && $b instanceof OrderedFixtureInterface) { if ($a->getOrder() === $b->getOrder()) { return 0; } return $a->getOrder() < $b->getOrder() ? -1 : 1; } if ($a instanceof OrderedFixtureInterface) { return $a->getOrder() === 0 ? 0 : 1; } if ($b instanceof OrderedFixtureInterface) { return $b->getOrder() === 0 ? 0 : -1; } return 0; }); } /** * Orders fixtures by dependencies * * @return void */ private function orderFixturesByDependencies() { $sequenceForClasses = []; // If fixtures were already ordered by number then we need // to remove classes which are not instances of OrderedFixtureInterface // in case fixtures implementing DependentFixtureInterface exist. // This is because, in that case, the method orderFixturesByDependencies // will handle all fixtures which are not instances of // OrderedFixtureInterface if ($this->orderFixturesByNumber) { $count = count($this->orderedFixtures); for ($i = 0; $i < $count; ++$i) { if ($this->orderedFixtures[$i] instanceof OrderedFixtureInterface) { continue; } unset($this->orderedFixtures[$i]); } } // First we determine which classes has dependencies and which don't foreach ($this->fixtures as $fixture) { $fixtureClass = get_class($fixture); if ($fixture instanceof OrderedFixtureInterface) { continue; } if ($fixture instanceof DependentFixtureInterface) { $dependenciesClasses = $fixture->getDependencies(); $this->validateDependencies($dependenciesClasses); if (! is_array($dependenciesClasses) || empty($dependenciesClasses)) { throw new InvalidArgumentException(sprintf('Method "%s" in class "%s" must return an array of classes which are dependencies for the fixture, and it must be NOT empty.', 'getDependencies', $fixtureClass)); } if (in_array($fixtureClass, $dependenciesClasses)) { throw new InvalidArgumentException(sprintf('Class "%s" can\'t have itself as a dependency', $fixtureClass)); } // We mark this class as unsequenced $sequenceForClasses[$fixtureClass] = -1; } else { // This class has no dependencies, so we assign 0 $sequenceForClasses[$fixtureClass] = 0; } } // Now we order fixtures by sequence $sequence = 1; $lastCount = -1; while (($count = count($unsequencedClasses = $this->getUnsequencedClasses($sequenceForClasses))) > 0 && $count !== $lastCount) { foreach ($unsequencedClasses as $key => $class) { $fixture = $this->fixtures[$class]; $dependencies = $fixture->getDependencies(); $unsequencedDependencies = $this->getUnsequencedClasses($sequenceForClasses, $dependencies); if (count($unsequencedDependencies) !== 0) { continue; } $sequenceForClasses[$class] = $sequence++; } $lastCount = $count; } $orderedFixtures = []; // If there're fixtures unsequenced left and they couldn't be sequenced, // it means we have a circular reference if ($count > 0) { $msg = 'Classes "%s" have produced a CircularReferenceException. '; $msg .= 'An example of this problem would be the following: Class C has class B as its dependency. '; $msg .= 'Then, class B has class A has its dependency. Finally, class A has class C as its dependency. '; $msg .= 'This case would produce a CircularReferenceException.'; throw new CircularReferenceException(sprintf($msg, implode(',', $unsequencedClasses))); } else { // We order the classes by sequence asort($sequenceForClasses); foreach ($sequenceForClasses as $class => $sequence) { // If fixtures were ordered $orderedFixtures[] = $this->fixtures[$class]; } } $this->orderedFixtures = array_merge($this->orderedFixtures, $orderedFixtures); } private function validateDependencies($dependenciesClasses) { $loadedFixtureClasses = array_keys($this->fixtures); foreach ($dependenciesClasses as $class) { if (! in_array($class, $loadedFixtureClasses)) { throw new RuntimeException(sprintf('Fixture "%s" was declared as a dependency, but it should be added in fixture loader first.', $class)); } } return true; } private function getUnsequencedClasses($sequences, $classes = null) { $unsequencedClasses = []; if ($classes === null) { $classes = array_keys($sequences); } foreach ($classes as $class) { if ($sequences[$class] !== -1) { continue; } $unsequencedClasses[] = $class; } return $unsequencedClasses; } /** * Load fixtures from files contained in iterator. * * @param Iterator $iterator Iterator over files from which fixtures should be loaded. * * @return array $fixtures Array of loaded fixture object instances. */ private function loadFromIterator(Iterator $iterator) { $includedFiles = []; foreach ($iterator as $file) { $fileName = $file->getBasename($this->fileExtension); if ($fileName === $file->getBasename()) { continue; } $sourceFile = realpath($file->getPathName()); require_once $sourceFile; $includedFiles[] = $sourceFile; } $fixtures = []; $declared = get_declared_classes(); // Make the declared classes order deterministic sort($declared); foreach ($declared as $className) { $reflClass = new ReflectionClass($className); $sourceFile = $reflClass->getFileName(); if (! in_array($sourceFile, $includedFiles) || $this->isTransient($className)) { continue; } $fixture = $this->createFixture($className); $fixtures[] = $fixture; $this->addFixture($fixture); } return $fixtures; } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php000066400000000000000000000006041361230416200323230ustar00rootroot00000000000000getManager()->getUnitOfWork(); $simpleReferences = []; foreach ($this->getReferences() as $name => $reference) { $className = $this->getRealClass(get_class($reference)); $simpleReferences[$name] = [$className, $this->getIdentifier($reference, $unitOfWork)]; } return serialize([ 'references' => $simpleReferences, 'identities' => $this->getIdentities(), ]); } /** * Unserialize reference repository * * @param string $serializedData Serialized data */ public function unserialize($serializedData) { $repositoryData = unserialize($serializedData); $references = $repositoryData['references']; foreach ($references as $name => $proxyReference) { $this->setReference( $name, $this->getManager()->getReference( $proxyReference[0], // entity class name $proxyReference[1] // identifiers ) ); } $identities = $repositoryData['identities']; foreach ($identities as $name => $identity) { $this->setReferenceIdentity($name, $identity); } } /** * Load data fixture reference repository * * @param string $baseCacheName Base cache name * * @return bool */ public function load($baseCacheName) { $filename = $baseCacheName . '.ser'; if (! file_exists($filename)) { return false; } $serializedData = file_get_contents($filename); if ($serializedData === false) { return false; } $this->unserialize($serializedData); return true; } /** * Save data fixture reference repository * * @param string $baseCacheName Base cache name */ public function save($baseCacheName) { $serializedData = $this->serialize(); file_put_contents($baseCacheName . '.ser', $serializedData); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Purger/000077500000000000000000000000001361230416200263025ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Purger/MongoDBPurger.php000066400000000000000000000025231361230416200314670ustar00rootroot00000000000000dm = $dm; } /** * Set the DocumentManager instance this purger instance should use. */ public function setDocumentManager(DocumentManager $dm) { $this->dm = $dm; } /** * Retrieve the DocumentManager instance this purger instance is using. * * @return DocumentManager */ public function getObjectManager() { return $this->dm; } /** @inheritDoc */ public function purge() { $metadatas = $this->dm->getMetadataFactory()->getAllMetadata(); foreach ($metadatas as $metadata) { if ($metadata->isMappedSuperclass) { continue; } $this->dm->getDocumentCollection($metadata->name)->drop(); } $this->dm->getSchemaManager()->ensureIndexes(); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Purger/ORMPurger.php000066400000000000000000000207421361230416200306420ustar00rootroot00000000000000em = $em; $this->excluded = $excluded; } /** * Set the purge mode * * @param int $mode * * @return void */ public function setPurgeMode($mode) { $this->purgeMode = $mode; } /** * Get the purge mode * * @return int */ public function getPurgeMode() { return $this->purgeMode; } /** * Set the EntityManagerInterface instance this purger instance should use. */ public function setEntityManager(EntityManagerInterface $em) { $this->em = $em; } /** * Retrieve the EntityManagerInterface instance this purger instance is using. * * @return EntityManagerInterface */ public function getObjectManager() { return $this->em; } /** @inheritDoc */ public function purge() { $classes = []; foreach ($this->em->getMetadataFactory()->getAllMetadata() as $metadata) { if ($metadata->isMappedSuperclass || (isset($metadata->isEmbeddedClass) && $metadata->isEmbeddedClass)) { continue; } $classes[] = $metadata; } $commitOrder = $this->getCommitOrder($this->em, $classes); // Get platform parameters $platform = $this->em->getConnection()->getDatabasePlatform(); // Drop association tables first $orderedTables = $this->getAssociationTables($commitOrder, $platform); // Drop tables in reverse commit order for ($i = count($commitOrder) - 1; $i >= 0; --$i) { $class = $commitOrder[$i]; if ((isset($class->isEmbeddedClass) && $class->isEmbeddedClass) || $class->isMappedSuperclass || ($class->isInheritanceTypeSingleTable() && $class->name !== $class->rootEntityName) ) { continue; } $orderedTables[] = $this->getTableName($class, $platform); } $connection = $this->em->getConnection(); $filterExpr = $connection->getConfiguration()->getFilterSchemaAssetsExpression(); $emptyFilterExpression = empty($filterExpr); $schemaAssetsFilter = method_exists($connection->getConfiguration(), 'getSchemaAssetsFilter') ? $connection->getConfiguration()->getSchemaAssetsFilter() : null; foreach ($orderedTables as $tbl) { // If we have a filter expression, check it and skip if necessary if (! $emptyFilterExpression && ! preg_match($filterExpr, $tbl)) { continue; } // If the table is excluded, skip it as well if (array_search($tbl, $this->excluded) !== false) { continue; } // Support schema asset filters as presented in if (is_callable($schemaAssetsFilter) && ! $schemaAssetsFilter($tbl)) { continue; } if ($this->purgeMode === self::PURGE_MODE_DELETE) { $connection->executeUpdate($this->getDeleteFromTableSQL($tbl, $platform)); } else { $connection->executeUpdate($platform->getTruncateTableSQL($tbl, true)); } } } /** * @param ClassMetadata[] $classes * * @return ClassMetadata[] */ private function getCommitOrder(EntityManagerInterface $em, array $classes) { $sorter = new TopologicalSorter(); foreach ($classes as $class) { if (! $sorter->hasNode($class->name)) { $sorter->addNode($class->name, $class); } // $class before its parents foreach ($class->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); $parentClassName = $parentClass->getName(); if (! $sorter->hasNode($parentClassName)) { $sorter->addNode($parentClassName, $parentClass); } $sorter->addDependency($class->name, $parentClassName); } foreach ($class->associationMappings as $assoc) { if (! $assoc['isOwningSide']) { continue; } /** @var ClassMetadata $targetClass */ $targetClass = $em->getClassMetadata($assoc['targetEntity']); $targetClassName = $targetClass->getName(); if (! $sorter->hasNode($targetClassName)) { $sorter->addNode($targetClassName, $targetClass); } // add dependency ($targetClass before $class) $sorter->addDependency($targetClassName, $class->name); // parents of $targetClass before $class, too foreach ($targetClass->parentClasses as $parentClass) { $parentClass = $em->getClassMetadata($parentClass); $parentClassName = $parentClass->getName(); if (! $sorter->hasNode($parentClassName)) { $sorter->addNode($parentClassName, $parentClass); } $sorter->addDependency($parentClassName, $class->name); } } } return array_reverse($sorter->sort()); } /** * @param array $classes * * @return array */ private function getAssociationTables(array $classes, AbstractPlatform $platform) { $associationTables = []; foreach ($classes as $class) { foreach ($class->associationMappings as $assoc) { if (! $assoc['isOwningSide'] || $assoc['type'] !== ClassMetadata::MANY_TO_MANY) { continue; } $associationTables[] = $this->getJoinTableName($assoc, $class, $platform); } } return $associationTables; } private function getTableName(ClassMetadata $class, AbstractPlatform $platform) : string { if (isset($class->table['schema']) && ! method_exists($class, 'getSchemaName')) { return $class->table['schema'] . '.' . $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } return $this->em->getConfiguration()->getQuoteStrategy()->getTableName($class, $platform); } /** * @param array $association * @param ClassMetadata $class * @param AbstractPlatform $platform * * @return string */ private function getJoinTableName($assoc, $class, $platform) { if (isset($assoc['joinTable']['schema']) && ! method_exists($class, 'getSchemaName')) { return $assoc['joinTable']['schema'] . '.' . $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } return $this->em->getConfiguration()->getQuoteStrategy()->getJoinTableName($assoc, $class, $platform); } private function getDeleteFromTableSQL(string $tableName, AbstractPlatform $platform) : string { $tableIdentifier = new Identifier($tableName); return 'DELETE FROM ' . $tableIdentifier->getQuotedName($platform); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Purger/PHPCRPurger.php000066400000000000000000000015551361230416200310620ustar00rootroot00000000000000dm = $dm; } public function setDocumentManager(DocumentManager $dm) { $this->dm = $dm; } public function getObjectManager() { return $this->dm; } /** * @inheritDoc */ public function purge() { $session = $this->dm->getPhpcrSession(); NodeHelper::purgeWorkspace($session); $session->save(); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php000066400000000000000000000004271361230416200321030ustar00rootroot00000000000000manager = $manager; } /** * Get identifier for a unit of work * * @param object $reference Reference object * @param object $uow Unit of work * * @return array */ protected function getIdentifier($reference, $uow) { // In case Reference is not yet managed in UnitOfWork if (! $this->hasIdentifier($reference)) { $class = $this->manager->getClassMetadata(get_class($reference)); return $class->getIdentifierValues($reference); } // Dealing with ORM UnitOfWork if (method_exists($uow, 'getEntityIdentifier')) { return $uow->getEntityIdentifier($reference); } // PHPCR ODM UnitOfWork if ($this->manager instanceof PhpcrDocumentManager) { return $uow->getDocumentId($reference); } // ODM UnitOfWork return $uow->getDocumentIdentifier($reference); } /** * Set the reference entry identified by $name * and referenced to $reference. If $name * already is set, it overrides it * * @param string $name * @param object $reference */ public function setReference($name, $reference) { $this->references[$name] = $reference; if (! $this->hasIdentifier($reference)) { return; } // in case if reference is set after flush, store its identity $uow = $this->manager->getUnitOfWork(); $this->identities[$name] = $this->getIdentifier($reference, $uow); } /** * Store the identifier of a reference * * @param string $name * @param mixed $identity */ public function setReferenceIdentity($name, $identity) { $this->identities[$name] = $identity; } /** * Set the reference entry identified by $name * and referenced to managed $object. $name must * not be set yet * * Notice: in case if identifier is generated after * the record is inserted, be sure tu use this method * after $object is flushed * * @param string $name * @param object $object - managed object * * @return void * * @throws BadMethodCallException - if repository already has a reference by $name. */ public function addReference($name, $object) { if (isset($this->references[$name])) { throw new BadMethodCallException(sprintf('Reference to "%s" already exists, use method setReference in order to override it', $name)); } $this->setReference($name, $object); } /** * Loads an object using stored reference * named by $name * * @param string $name * * @return object * * @throws OutOfBoundsException - if repository does not exist. */ public function getReference($name) { if (! $this->hasReference($name)) { throw new OutOfBoundsException(sprintf('Reference to "%s" does not exist', $name)); } $reference = $this->references[$name]; $meta = $this->manager->getClassMetadata(get_class($reference)); if (! $this->manager->contains($reference) && isset($this->identities[$name])) { $reference = $this->manager->getReference( $meta->name, $this->identities[$name] ); $this->references[$name] = $reference; // already in identity map } return $reference; } /** * Check if an object is stored using reference * named by $name * * @param string $name * * @return bool */ public function hasReference($name) { return isset($this->references[$name]); } /** * Searches for reference names in the * list of stored references * * @param object $reference * * @return array */ public function getReferenceNames($reference) { return array_keys($this->references, $reference, true); } /** * Checks if reference has identity stored * * @param string $name */ public function hasIdentity($name) { return array_key_exists($name, $this->identities); } /** * Get all stored identities * * @return array */ public function getIdentities() { return $this->identities; } /** * Get all stored references * * @return array */ public function getReferences() { return $this->references; } /** * Get object manager * * @return ObjectManager */ public function getManager() { return $this->manager; } /** * Checks if object has identifier already in unit of work. * * @param string $reference * * @return bool */ private function hasIdentifier($reference) { // in case if reference is set after flush, store its identity $uow = $this->manager->getUnitOfWork(); if ($this->manager instanceof PhpcrDocumentManager) { return $uow->contains($reference); } return $uow->isInIdentityMap($reference); } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php000066400000000000000000000006331361230416200321470ustar00rootroot00000000000000allowCyclicDependencies = $allowCyclicDependencies; } /** * Adds a new node (vertex) to the graph, assigning its hash and value. * * @param string $hash * * @return void */ public function addNode($hash, ClassMetadata $node) { $this->nodeList[$hash] = new Vertex($node); } /** * Checks the existence of a node in the graph. * * @param string $hash * * @return bool */ public function hasNode($hash) { return isset($this->nodeList[$hash]); } /** * Adds a new dependency (edge) to the graph using their hashes. * * @param string $fromHash * @param string $toHash * * @return void */ public function addDependency($fromHash, $toHash) { $definition = $this->nodeList[$fromHash]; $definition->dependencyList[] = $toHash; } /** * Return a valid order list of all current nodes. * The desired topological sorting is the postorder of these searches. * * Note: Highly performance-sensitive method. * * @return array * * @throws RuntimeException * @throws CircularReferenceException */ public function sort() { foreach ($this->nodeList as $definition) { if ($definition->state !== Vertex::NOT_VISITED) { continue; } $this->visit($definition); } $sortedList = $this->sortedNodeList; $this->nodeList = []; $this->sortedNodeList = []; return $sortedList; } /** * Visit a given node definition for reordering. * * Note: Highly performance-sensitive method. * * @throws RuntimeException * @throws CircularReferenceException */ private function visit(Vertex $definition) { $definition->state = Vertex::IN_PROGRESS; foreach ($definition->dependencyList as $dependency) { if (! isset($this->nodeList[$dependency])) { throw new RuntimeException(sprintf( 'Fixture "%s" has a dependency of fixture "%s", but it not listed to be loaded.', get_class($definition->value), $dependency )); } $childDefinition = $this->nodeList[$dependency]; // allow self referencing classes if ($definition === $childDefinition) { continue; } switch ($childDefinition->state) { case Vertex::VISITED: break; case Vertex::IN_PROGRESS: if (! $this->allowCyclicDependencies) { throw new CircularReferenceException( sprintf( 'Graph contains cyclic dependency between the classes "%s" and' . ' "%s". An example of this problem would be the following: ' . 'Class C has class B as its dependency. Then, class B has class A has its dependency. ' . 'Finally, class A has class C as its dependency.', $definition->value->getName(), $childDefinition->value->getName() ) ); } break; case Vertex::NOT_VISITED: $this->visit($childDefinition); } } $definition->state = Vertex::VISITED; $this->sortedNodeList[] = $definition->value; } } php-doctrine-data-fixtures-1.4.2/lib/Doctrine/Common/DataFixtures/Sorter/Vertex.php000066400000000000000000000016501361230416200303040ustar00rootroot00000000000000value = $value; } } php-doctrine-data-fixtures-1.4.2/phpcs.xml.dist000066400000000000000000000047021361230416200214720ustar00rootroot00000000000000 lib tests tests/* lib/Doctrine/Common/DataFixtures/AbstractFixture.php lib/Doctrine/Common/DataFixtures/Executor/AbstractExecutor.php lib/Doctrine/Common/DataFixtures/Exception/CircularReferenceException.php lib/Doctrine/Common/DataFixtures/DependentFixtureInterface.php lib/Doctrine/Common/DataFixtures/FixtureInterface.php lib/Doctrine/Common/DataFixtures/Purger/PurgerInterface.php lib/Doctrine/Common/DataFixtures/OrderedFixtureInterface.php lib/Doctrine/Common/DataFixtures/SharedFixtureInterface.php tests/* php-doctrine-data-fixtures-1.4.2/phpunit.xml.dist000066400000000000000000000012001361230416200220320ustar00rootroot00000000000000 ./tests/Doctrine/ ./lib/Doctrine/ php-doctrine-data-fixtures-1.4.2/tests/000077500000000000000000000000001361230416200200305ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/000077500000000000000000000000001361230416200215775ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/000077500000000000000000000000001361230416200227015ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/000077500000000000000000000000001361230416200241315ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/000077500000000000000000000000001361230416200265345ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/BaseTest.php000066400000000000000000000022311361230416200307550ustar00rootroot00000000000000 'pdo_sqlite', 'memory' => true]; $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true, null, null, false); return EntityManager::create($dbParams, $config); } /** * EntityManager mock object together with * annotation mapping driver and pdo_sqlite * database in memory * * @return EntityManager */ protected function getMockSqliteEntityManager() { $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/TestEntity'], true, null, null, false); return EntityManager::create($dbParams, $config); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/DependentFixtureTest.php000066400000000000000000000254101361230416200333640ustar00rootroot00000000000000addFixture(new DependentFixture3()); $loader->addFixture(new DependentFixture1()); $loader->addFixture(new DependentFixture2()); $loader->addFixture(new BaseParentFixture1()); $orderedFixtures = $loader->getFixtures(); $this->assertCount(4, $orderedFixtures); $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture2::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } public function testOrderFixturesByDependenciesOrderClassesWithAMultipleParents() { $loader = new Loader(); $addressFixture = new AddressFixture(); $contactMethodFixture = new ContactMethodFixture(); $contactFixture = new ContactFixture(); $baseParentFixture = new BaseParentFixture1(); $countryFixture = new CountryFixture(); $stateFixture = new StateFixture(); $loader->addFixture($addressFixture); $loader->addFixture($contactMethodFixture); $loader->addFixture($contactFixture); $loader->addFixture($baseParentFixture); $loader->addFixture($countryFixture); $loader->addFixture($stateFixture); $orderedFixtures = $loader->getFixtures(); $this->assertCount(6, $orderedFixtures); $contactFixtureOrder = array_search($contactFixture, $orderedFixtures); $contactMethodFixtureOrder = array_search($contactMethodFixture, $orderedFixtures); $addressFixtureOrder = array_search($addressFixture, $orderedFixtures); $countryFixtureOrder = array_search($countryFixture, $orderedFixtures); $stateFixtureOrder = array_search($stateFixture, $orderedFixtures); $baseParentFixtureOrder = array_search($baseParentFixture, $orderedFixtures); // Order of fixtures is not exact. We need to test, however, that dependencies are // indeed satisfied // BaseParentFixture1 has no dependencies, so it will always be first in this case $this->assertEquals($baseParentFixtureOrder, 0); $this->assertGreaterThan($contactMethodFixtureOrder, $contactFixtureOrder); $this->assertGreaterThan($addressFixtureOrder, $contactFixtureOrder); $this->assertGreaterThan($countryFixtureOrder, $contactFixtureOrder); $this->assertGreaterThan($stateFixtureOrder, $contactFixtureOrder); $this->assertGreaterThan($contactMethodFixtureOrder, $contactFixtureOrder); $this->assertGreaterThan($stateFixtureOrder, $addressFixtureOrder); $this->assertGreaterThan($countryFixtureOrder, $addressFixtureOrder); } public function testOrderFixturesByDependenciesCircularReferencesMakeMethodThrowCircularReferenceException() { $loader = new Loader(); $loader->addFixture(new CircularReferenceFixture3()); $loader->addFixture(new CircularReferenceFixture()); $loader->addFixture(new CircularReferenceFixture2()); $this->expectException(CircularReferenceException::class); $loader->getFixtures(); } public function testOrderFixturesByDependenciesFixturesCantHaveItselfAsParent() { $loader = new Loader(); $loader->addFixture(new FixtureWithItselfAsParent()); $this->expectException(InvalidArgumentException::class); $loader->getFixtures(); } public function testInCaseThereAreFixturesOrderedByNumberAndByDependenciesBothOrdersAreExecuted() { $loader = new Loader(); $loader->addFixture(new OrderedByNumberFixture1()); $loader->addFixture(new OrderedByNumberFixture3()); $loader->addFixture(new OrderedByNumberFixture2()); $loader->addFixture(new DependentFixture3()); $loader->addFixture(new DependentFixture1()); $loader->addFixture(new DependentFixture2()); $loader->addFixture(new BaseParentFixture1()); $orderedFixtures = $loader->getFixtures(); $this->assertCount(7, $orderedFixtures); $this->assertInstanceOf(OrderedByNumberFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(OrderedByNumberFixture2::class, array_shift($orderedFixtures)); $this->assertInstanceOf(OrderedByNumberFixture3::class, array_shift($orderedFixtures)); $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture2::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture3::class, array_shift($orderedFixtures)); } public function testInCaseAFixtureHasAnUnexistentDependencyOrIfItWasntLoadedThrowsException() { $loader = new Loader(); $loader->addFixture(new FixtureWithUnexistentDependency()); $this->expectException(RuntimeException::class); $loader->getFixtures(); } public function testInCaseGetFixturesReturnsDifferentResultsEachTime() { $loader = new Loader(); $loader->addFixture(new DependentFixture1()); $loader->addFixture(new BaseParentFixture1()); // Intentionally calling getFixtures() twice $loader->getFixtures(); $orderedFixtures = $loader->getFixtures(); $this->assertCount(2, $orderedFixtures); $this->assertInstanceOf(BaseParentFixture1::class, array_shift($orderedFixtures)); $this->assertInstanceOf(DependentFixture1::class, array_shift($orderedFixtures)); } } class DependentFixture1 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [BaseParentFixture1::class]; } } class DependentFixture2 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [DependentFixture1::class]; } } class DependentFixture3 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [DependentFixture2::class]; } } class BaseParentFixture1 implements FixtureInterface { public function load(ObjectManager $manager) { } } class CountryFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [BaseParentFixture1::class]; } } class StateFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [ BaseParentFixture1::class, CountryFixture::class, ]; } } class AddressFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [ BaseParentFixture1::class, CountryFixture::class, StateFixture::class, ]; } } class ContactMethodFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [BaseParentFixture1::class]; } } class ContactFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [ AddressFixture::class, ContactMethodFixture::class, ]; } } class CircularReferenceFixture implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [CircularReferenceFixture3::class]; } } class CircularReferenceFixture2 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [CircularReferenceFixture::class]; } } class CircularReferenceFixture3 implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [CircularReferenceFixture2::class]; } } class FixtureWithItselfAsParent implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return [self::class]; } } class FixtureWithUnexistentDependency implements FixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getDependencies() { return ['UnexistentDependency']; } } class FixtureImplementingBothOrderingInterfaces implements FixtureInterface, OrderedFixtureInterface, DependentFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 1; } public function getDependencies() { return [FixtureWithItselfAsParent::class]; } } class OrderedByNumberFixture1 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 1; } } class OrderedByNumberFixture2 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 5; } } class OrderedByNumberFixture3 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 10; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/Executor/000077500000000000000000000000001361230416200303325ustar00rootroot00000000000000ORMExecutorSharedFixtureTest.php000066400000000000000000000052061361230416200365010ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/ExecutorgetMockAnnotationReaderEntityManager(); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $referenceRepository = $executor->getReferenceRepository(); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); $fixture->expects($this->once()) ->method('setReferenceRepository') ->with($referenceRepository); $executor->execute([$fixture], true); } public function testSharedFixtures() { if (! extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Missing pdo_sqlite extension.'); } $em = $this->getMockSqliteEntityManager(); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_ROLE), $em->getClassMetadata(self::TEST_ENTITY_USER), ]); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $userFixture = new TestFixtures\UserFixture(); $roleFixture = new TestFixtures\RoleFixture(); $executor->execute([$roleFixture, $userFixture], true); $referenceRepository = $executor->getReferenceRepository(); $references = $referenceRepository->getReferences(); $this->assertCount(2, $references); $roleReference = $referenceRepository->getReference('admin-role'); $this->assertInstanceOf(Role::class, $roleReference); $this->assertEquals('admin', $roleReference->getName()); $userReference = $referenceRepository->getReference('admin'); $this->assertInstanceOf(User::class, $userReference); $this->assertEquals('admin@example.com', $userReference->getEmail()); } private function getMockFixture() { return $this->createMock(SharedFixtureInterface::class); } } ORMExecutorTest.php000066400000000000000000000036141361230416200340040ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/ExecutorgetMockSqliteEntityManager(); $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('setEntityManager') ->with($em); $executor = new ORMExecutor($em, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); $executor->execute([$fixture], true); } public function testExecuteWithPurge() { $em = $this->getMockSqliteEntityManager(); $purger = $this->getMockPurger(); $purger->expects($this->once()) ->method('purge') ->will($this->returnValue(null)); $executor = new ORMExecutor($em, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); $executor->execute([$fixture], false); } public function testExecuteTransaction() { $em = $this->getMockSqliteEntityManager(); $executor = new ORMExecutor($em); $fixture = $this->getMockFixture(); $fixture->expects($this->once()) ->method('load') ->with($em); $executor->execute([$fixture], true); } private function getMockFixture() { return $this->createMock(FixtureInterface::class); } private function getMockPurger() { return $this->createMock(ORMPurger::class); } } PHPCRExecutorTest.php000066400000000000000000000116031361230416200342200ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/ExecutorgetDocumentManager(); $executor = new PHPCRExecutor($dm); $fixture = $this->getMockFixture(); $fixture->expects($this->once())->method('load')->with($dm); $dm ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $executor->execute([$fixture], true); } public function testExecuteMultipleFixturesWithNoPurge() { $dm = $this->getDocumentManager(); $executor = new PHPCRExecutor($dm); $fixture1 = $this->getMockFixture(); $fixture2 = $this->getMockFixture(); $fixture1->expects($this->once())->method('load')->with($dm); $fixture2->expects($this->once())->method('load')->with($dm); $dm ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $executor->execute([$fixture1, $fixture2], true); } public function testExecuteFixtureWithPurge() { $dm = $this->getDocumentManager(); $purger = $this->getPurger(); $executor = new PHPCRExecutor($dm, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once())->method('load')->with($dm); $dm ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $purger->expects($this->once())->method('purge'); $executor->execute([$fixture], false); } public function testExecuteFixtureWithoutPurge() { $dm = $this->getDocumentManager(); $purger = $this->getPurger(); $executor = new PHPCRExecutor($dm, $purger); $fixture = $this->getMockFixture(); $fixture->expects($this->once())->method('load')->with($dm); $dm ->expects($this->once()) ->method('transactional') ->with($this->isType('callable')) ->will($this->returnCallback(static function ($callback) use ($dm) { return $callback($dm); })); $purger->expects($this->never())->method('purge'); $executor->execute([$fixture], true); } public function testFailedTransactionalStopsPurgingAndFixtureLoading() { $dm = $this->getDocumentManager(); $purger = $this->getPurger(); $executor = new PHPCRExecutor($dm, $purger); $fixture = $this->getMockFixture(); $exception = new Exception(); $fixture->expects($this->never())->method('load'); $dm->expects($this->once())->method('transactional')->will($this->throwException($exception)); $purger->expects($this->never())->method('purge'); try { $executor->execute([$fixture], true); } catch (Throwable $caughtException) { $this->assertSame($exception, $caughtException); } } /** * @return PHPCRPurger|PHPUnit_Framework_MockObject_MockObject */ private function getPurger() { return $this->createMock(PHPCRPurger::class); } /** * @return DocumentManager|PHPUnit_Framework_MockObject_MockObject */ private function getDocumentManager() { if (! class_exists(DocumentManager::class)) { $this->markTestSkipped('Missing doctrine/phpcr-odm'); } return $this ->getMockBuilder(DocumentManager::class) ->setMethods([ 'transactional', 'flush', 'clear', ]) ->disableOriginalConstructor() ->getMock(); } /** * @return FixtureInterface|PHPUnit_Framework_MockObject_MockObject */ private function getMockFixture() { return $this->createMock(FixtureInterface::class); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/FixtureTest.php000066400000000000000000000012271361230416200315350ustar00rootroot00000000000000createMock(ObjectManager::class); $fixture = new MyFixture2(); $fixture->load($em); self::assertTrue($fixture->loaded); } } class MyFixture2 implements FixtureInterface { /** @var bool */ public $loaded = false; public function load(ObjectManager $manager) { $this->loaded = true; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/LoaderTest.php000066400000000000000000000045451361230416200313230ustar00rootroot00000000000000addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock()); $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock()); $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock()); $this->assertCount(3, $loader->getFixtures()); $loader->loadFromDirectory(__DIR__ . '/TestFixtures'); $this->assertCount(7, $loader->getFixtures()); $this->assertTrue($loader->isTransient(NotAFixture::class)); $this->assertFalse($loader->isTransient(MyFixture1::class)); } public function testLoadFromFile() { $loader = new Loader(); $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock()); $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock()); $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock()); $this->assertCount(3, $loader->getFixtures()); $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php'); $this->assertCount(4, $loader->getFixtures()); $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php'); $this->assertCount(4, $loader->getFixtures()); $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php'); $this->assertCount(5, $loader->getFixtures()); $this->assertTrue($loader->isTransient(NotAFixture::class)); $this->assertFalse($loader->isTransient(MyFixture1::class)); } public function testGetFixture() { $loader = new Loader(); $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php'); $fixture = $loader->getFixture(MyFixture1::class); $this->assertInstanceOf(MyFixture1::class, $fixture); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/OrderedFixtureTest.php000066400000000000000000000033541361230416200330450ustar00rootroot00000000000000addFixture(new OrderedFixture1()); $loader->addFixture(new OrderedFixture2()); $loader->addFixture(new OrderedFixture3()); $loader->addFixture(new BaseFixture1()); $orderedFixtures = $loader->getFixtures(); $this->assertCount(4, $orderedFixtures); $this->assertInstanceOf(BaseFixture1::class, $orderedFixtures[0]); $this->assertInstanceOf(OrderedFixture2::class, $orderedFixtures[1]); $this->assertInstanceOf(OrderedFixture1::class, $orderedFixtures[2]); $this->assertInstanceOf(OrderedFixture3::class, $orderedFixtures[3]); } } class OrderedFixture1 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 5; } } class OrderedFixture2 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 2; } } class OrderedFixture3 implements FixtureInterface, OrderedFixtureInterface { public function load(ObjectManager $manager) { } public function getOrder() { return 8; } } class BaseFixture1 implements FixtureInterface { public function load(ObjectManager $manager) { } } ProxyReferenceRepositoryTest.php000066400000000000000000000152061361230416200350720ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixturesgetMockAnnotationReaderEntityManager(); $role = new TestEntity\Role(); $role->setName('admin'); $meta = $em->getClassMetadata(self::TEST_ENTITY_ROLE); $meta->getReflectionProperty('id')->setValue($role, 1); $referenceRepo = new ProxyReferenceRepository($em); $referenceRepo->addReference('test', $role); $references = $referenceRepo->getReferences(); $this->assertCount(1, $references); $this->assertArrayHasKey('test', $references); $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $references['test']); } public function testReferenceIdentityPopulation() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = $this->getMockBuilder(ProxyReferenceRepository::class) ->setConstructorArgs([$em]) ->getMock(); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); $referenceRepository->expects($this->once()) ->method('addReference') ->with('admin-role'); $referenceRepository->expects($this->once()) ->method('getReferenceNames') ->will($this->returnValue(['admin-role'])); $referenceRepository->expects($this->once()) ->method('setReferenceIdentity') ->with('admin-role', ['id' => 1]); $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); } public function testReferenceReconstruction() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ProxyReferenceRepository($em); $listener = new ORMReferenceListener($referenceRepository); $em->getEventManager()->addEventSubscriber($listener); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); // first test against managed state $ref = $referenceRepository->getReference('admin-role'); $this->assertNotInstanceOf(Proxy::class, $ref); // test reference reconstruction from serialized data (was managed) $serializedData = $referenceRepository->serialize(); $proxyReferenceRepository = new ProxyReferenceRepository($em); $proxyReferenceRepository->unserialize($serializedData); $ref = $proxyReferenceRepository->getReference('admin-role'); // before clearing, the reference is not yet a proxy $this->assertNotInstanceOf(Proxy::class, $ref); $this->assertInstanceOf(self::TEST_ENTITY_ROLE, $ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role'); $this->assertInstanceOf(Proxy::class, $ref); // test reference reconstruction from serialized data (was identity) $serializedData = $referenceRepository->serialize(); $proxyReferenceRepository = new ProxyReferenceRepository($em); $proxyReferenceRepository->unserialize($serializedData); $ref = $proxyReferenceRepository->getReference('admin-role'); $this->assertInstanceOf(Proxy::class, $ref); } public function testReconstructionOfCustomTypedId() : void { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ProxyReferenceRepository($em); $listener = new ORMReferenceListener($referenceRepository); $em->getEventManager()->addEventSubscriber($listener); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_LINK)]); $link = new TestEntity\Link(new Uuid('5e48c0d7-78c2-44f5-bed0-e7970b2822b8')); $link->setUrl('http://example.com'); $referenceRepository->addReference('home-link', $link); $em->persist($link); $em->flush(); $em->clear(); $serializedData = $referenceRepository->serialize(); $proxyReferenceRepository = new ProxyReferenceRepository($em); $proxyReferenceRepository->unserialize($serializedData); $this->assertInstanceOf( 'Doctrine\Tests\Common\DataFixtures\TestValueObjects\Uuid', $proxyReferenceRepository->getReference('home-link')->getId() ); } public function testReferenceMultipleEntries() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ProxyReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); $schemaTool->createSchema([$em->getClassMetadata(self::TEST_ENTITY_ROLE)]); $role = new TestEntity\Role(); $role->setName('admin'); $em->persist($role); $referenceRepository->addReference('admin', $role); $referenceRepository->addReference('duplicate', $role); $em->flush(); $em->clear(); $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin')); $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate')); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/Purger/000077500000000000000000000000001361230416200300005ustar00rootroot00000000000000MongoDBPurgerTest.php000066400000000000000000000042311361230416200337440ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/PurgermarkTestSkipped('Missing doctrine/mongodb-odm'); } $root = dirname(dirname(dirname(dirname(dirname(__DIR__))))); $config = new Configuration(); $config->setProxyDir($root . '/generate/proxies'); $config->setProxyNamespace('Proxies'); $config->setHydratorDir($root . '/generate/hydrators'); $config->setHydratorNamespace('Hydrators'); $config->setMetadataDriverImpl(AnnotationDriver::create(dirname(__DIR__) . '/TestDocument')); AnnotationDriver::registerAnnotationClasses(); $dm = DocumentManager::create(null, $config); if (! $dm->getConnection()->connect()) { $this->markTestSkipped('Unable to connect to MongoDB'); } return $dm; } private function getPurger() { return new MongoDBPurger($this->getDocumentManager()); } public function testPurgeKeepsIndices() { $purger = $this->getPurger(); $dm = $purger->getObjectManager(); $collection = $dm->getDocumentCollection(self::TEST_DOCUMENT_ROLE); $collection->drop(); $this->assertCount(0, $collection->getIndexInfo()); $role = new Role(); $role->setName('role'); $dm->persist($role); $dm->flush(); $schema = $dm->getSchemaManager()->ensureDocumentIndexes(self::TEST_DOCUMENT_ROLE); $this->assertCount(2, $collection->getIndexInfo()); $purger->purge(); $this->assertCount(2, $collection->getIndexInfo()); } } ORMPurgerExcludeTest.php000066400000000000000000000074631361230416200344400ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/PurgermarkTestSkipped('Missing pdo_sqlite extension.'); } $dbParams = ['driver' => 'pdo_sqlite', 'memory' => true]; $config = Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../TestPurgeEntity'], true, null, null, false); $em = EntityManager::create($dbParams, $config); $connection = $em->getConnection(); $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression(null); $schemaTool = new SchemaTool($em); $schemaTool->dropDatabase(); $schemaTool->createSchema([ $em->getClassMetadata(self::TEST_ENTITY_INCLUDED), $em->getClassMetadata(self::TEST_ENTITY_EXCLUDED), ]); $entity = new ExcludedEntity(); $entity->setId(1); $em->persist($entity); $entity = new IncludedEntity(); $entity->setId(1); $em->persist($entity); $em->flush(); return $em; } /** * Execute test purge * * @param string|null $expression * @param array $list */ public function executeTestPurge($expression, array $list, ?callable $filter = null) { $em = $this->loadTestData(); $excludedRepository = $em->getRepository(self::TEST_ENTITY_EXCLUDED); $includedRepository = $em->getRepository(self::TEST_ENTITY_INCLUDED); $excluded = $excludedRepository->findAll(); $included = $includedRepository->findAll(); $this->assertGreaterThan(0, count($included)); $this->assertGreaterThan(0, count($excluded)); $connection = $em->getConnection(); $configuration = $connection->getConfiguration(); $configuration->setFilterSchemaAssetsExpression($expression); if ($filter !== null) { if (! method_exists($configuration, 'setSchemaAssetsFilter')) { $this->markTestSkipped('DBAL 2.9 or newer is required to test schema assets filters'); } $configuration->setSchemaAssetsFilter($filter); } $purger = new ORMPurger($em, $list); $purger->purge(); $excluded = $excludedRepository->findAll(); $included = $includedRepository->findAll(); $this->assertCount(0, $included); $this->assertGreaterThan(0, count($excluded)); } /** * Test for purge exclusion usig dbal filter expression regexp. */ public function testPurgeExcludeUsingFilterExpression() { $this->executeTestPurge('~^(?!ExcludedEntity)~', [], null); } /** * Test for purge exclusion usig explicit exclution list. */ public function testPurgeExcludeUsingList() { $this->executeTestPurge(null, ['ExcludedEntity'], null); } public function testPurgeExcludeUsingFilterCallable() : void { $this->executeTestPurge(null, [], static function (string $table) : bool { return (bool) preg_match('~^(?!ExcludedEntity)~', $table); }); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/Purger/ORMPurgerTest.php000066400000000000000000000077211361230416200332020ustar00rootroot00000000000000getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], 'readers__author_reader'); } public function testGetAssociationTablesQuoted() { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_QUOTED); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getAssociationTables'); $method->setAccessible(true); $associationTables = $method->invokeArgs($purger, [[$metadata], $platform]); $this->assertEquals($associationTables[0], '"INSERT"'); } public function testTableNameWithSchema() { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_USER_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getTableName'); $method->setAccessible(true); $tableName = $method->invokeArgs($purger, [$metadata, $platform]); $this->assertStringStartsWith('test_schema', $tableName); } public function testGetDeleteFromTableSQL() : void { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_GROUP); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getTableName'); $method->setAccessible(true); $tableName = $method->invokeArgs($purger, [$metadata, $platform]); $method = $class->getMethod('getDeleteFromTableSQL'); $method->setAccessible(true); $sql = $method->invokeArgs($purger, [$tableName, $platform]); $this->assertEquals('DELETE FROM "Group"', $sql); } public function testGetDeleteFromTableSQLWithSchema() : void { $em = $this->getMockAnnotationReaderEntityManager(); $metadata = $em->getClassMetadata(self::TEST_ENTITY_GROUP_WITH_SCHEMA); $platform = $em->getConnection()->getDatabasePlatform(); $purger = new ORMPurger($em); $class = new ReflectionClass(ORMPurger::class); $method = $class->getMethod('getTableName'); $method->setAccessible(true); $tableName = $method->invokeArgs($purger, [$metadata, $platform]); $method = $class->getMethod('getDeleteFromTableSQL'); $method->setAccessible(true); $sql = $method->invokeArgs($purger, [$tableName, $platform]); $this->assertEquals('DELETE FROM test_schema__group', $sql); } } ReferenceRepositoryTest.php000066400000000000000000000173611361230416200340340ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixturesgetMockAnnotationReaderEntityManager(); $role = new TestEntity\Role(); $role->setName('admin'); $meta = $em->getClassMetadata(Role::class); $meta->getReflectionProperty('id')->setValue($role, 1); $referenceRepo = new ReferenceRepository($em); $this->assertSame($em, $referenceRepo->getManager()); $referenceRepo->addReference('test', $role); $references = $referenceRepo->getReferences(); $this->assertCount(1, $references); $this->assertArrayHasKey('test', $references); $this->assertInstanceOf(Role::class, $references['test']); } public function testReferenceIdentityPopulation() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = $this->getMockBuilder(ReferenceRepository::class) ->setConstructorArgs([$em]) ->getMock(); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $referenceRepository->expects($this->once()) ->method('addReference') ->with('admin-role'); $referenceRepository->expects($this->once()) ->method('getReferenceNames') ->will($this->returnValue(['admin-role'])); $referenceRepository->expects($this->once()) ->method('setReferenceIdentity') ->with('admin-role', ['id' => 1]); $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); } public function testReferenceReconstruction() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber( new ORMReferenceListener($referenceRepository) ); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $roleFixture = new TestFixtures\RoleFixture(); $roleFixture->setReferenceRepository($referenceRepository); $roleFixture->load($em); // first test against managed state $ref = $referenceRepository->getReference('admin-role'); $this->assertNotInstanceOf(Proxy::class, $ref); // now test reference reconstruction from identity $em->clear(); $ref = $referenceRepository->getReference('admin-role'); $this->assertInstanceOf(Proxy::class, $ref); } public function testReferenceMultipleEntries() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository)); $schemaTool = new SchemaTool($em); $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $role = new TestEntity\Role(); $role->setName('admin'); $em->persist($role); $referenceRepository->addReference('admin', $role); $referenceRepository->addReference('duplicate', $role); $em->flush(); $em->clear(); $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('admin')); $this->assertInstanceOf(Proxy::class, $referenceRepository->getReference('duplicate')); } public function testUndefinedReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Reference to "foo" does not exist'); $referenceRepository->getReference('foo'); } public function testThrowsExceptionAddingDuplicatedReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $referenceRepository->addReference('duplicated_reference', new stdClass()); $this->expectException(BadMethodCallException::class); $this->expectExceptionMessage('Reference to "duplicated_reference" already exists, use method setReference in order to override it'); $referenceRepository->addReference('duplicated_reference', new stdClass()); } public function testThrowsExceptionTryingToGetWrongReference() { $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Reference to "missing_reference" does not exist'); $referenceRepository->getReference('missing_reference'); } public function testHasIdentityCheck() { $role = new Role(); $referenceRepository = new ReferenceRepository($this->getMockSqliteEntityManager()); $referenceRepository->setReferenceIdentity('entity', $role); $this->assertTrue($referenceRepository->hasIdentity('entity')); $this->assertFalse($referenceRepository->hasIdentity('invalid_entity')); $this->assertEquals(['entity' => $role], $referenceRepository->getIdentities()); } public function testSetReferenceHavingIdentifier() { $em = $this->getMockSqliteEntityManager(); $referenceRepository = new ReferenceRepository($em); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema([$em->getClassMetadata(Role::class)]); $role = new Role(); $role->setName('role_name'); $em->persist($role); $em->flush(); $referenceRepository->setReference('entity', $role); $identities = $referenceRepository->getIdentities(); $this->assertCount(1, $identities); $this->assertArrayHasKey('entity', $identities); } public function testGetIdentifierWhenHasNotBeenManagedYetByUnitOfWork() { $role = new Role(); $identitiesExpected = ['id' => 1]; /** @var UnitOfWork | ProphecyInterface $uow */ $uow = $this->prophesize(UnitOfWork::class); $uow->isInIdentityMap($role)->shouldBeCalledTimes(2)->willReturn(true, false); /** @var ClassMetadata $classMetadata */ $classMetadata = $this->prophesize(ClassMetadata::class); $classMetadata->getIdentifierValues($role)->shouldBeCalled()->willReturn($identitiesExpected); /** @var EntityManagerInterface | ProphecyInterface $em */ $em = $this->prophesize(EntityManagerInterface::class); $em->getUnitOfWork()->shouldBeCalled()->willReturn($uow); $em->getClassMetadata(Role::class)->shouldBeCalled()->willReturn($classMetadata); $referenceRepository = new ReferenceRepository($em->reveal()); $referenceRepository->setReference('entity', $role); $identities = $referenceRepository->getIdentities(); $this->assertEquals($identitiesExpected, $identities['entity']); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/Sorter/000077500000000000000000000000001361230416200300125ustar00rootroot00000000000000TopologicalSorterTest.php000066400000000000000000000112761361230416200347660ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/SorteraddNode('1', $node1); $sorter->addNode('2', $node2); $sorter->addNode('3', $node3); $sorter->addNode('4', $node4); $sorter->addNode('5', $node5); $sorter->addDependency('1', '2'); $sorter->addDependency('2', '3'); $sorter->addDependency('3', '4'); $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); $correctList = [$node4, $node3, $node2, $node1, $node5]; self::assertSame($correctList, $sortedList); } public function testSuccessSortMultiDependency() { $sorter = new TopologicalSorter(); $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $node4 = new ClassMetadata(4); $node5 = new ClassMetadata(5); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); $sorter->addNode('3', $node3); $sorter->addNode('4', $node4); $sorter->addNode('5', $node5); $sorter->addDependency('3', '2'); $sorter->addDependency('3', '4'); $sorter->addDependency('3', '5'); $sorter->addDependency('4', '1'); $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); $correctList = [$node1, $node2, $node4, $node5, $node3]; self::assertSame($correctList, $sortedList); } public function testSortCyclicDependency() { $sorter = new TopologicalSorter(); $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); $sorter->addNode('3', $node3); $sorter->addDependency('1', '2'); $sorter->addDependency('2', '3'); $sorter->addDependency('3', '1'); $sortedList = $sorter->sort(); $correctList = [$node3, $node2, $node1]; self::assertSame($correctList, $sortedList); $sorter->sort(); } public function testFailureSortCyclicDependency() { $sorter = new TopologicalSorter(false); $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); $sorter->addNode('3', $node3); $sorter->addDependency('1', '2'); $sorter->addDependency('2', '3'); $sorter->addDependency('3', '1'); $this->expectException(CircularReferenceException::class); $sorter->sort(); } public function testNoFailureOnSelfReferencingDependency() { $sorter = new TopologicalSorter(); $node1 = new ClassMetadata(1); $node2 = new ClassMetadata(2); $node3 = new ClassMetadata(3); $node4 = new ClassMetadata(4); $node5 = new ClassMetadata(5); $sorter->addNode('1', $node1); $sorter->addNode('2', $node2); $sorter->addNode('3', $node3); $sorter->addNode('4', $node4); $sorter->addNode('5', $node5); $sorter->addDependency('1', '2'); $sorter->addDependency('1', '1'); $sorter->addDependency('2', '3'); $sorter->addDependency('3', '4'); $sorter->addDependency('5', '1'); $sortedList = $sorter->sort(); $correctList = [$node4, $node3, $node2, $node1, $node5]; self::assertSame($correctList, $sortedList); } public function testFailureSortMissingDependency() { $sorter = new TopologicalSorter(); $node1 = new ClassMetadata(1); $sorter->addNode('1', $node1); $sorter->addDependency('1', '2'); $this->expectException(RuntimeException::class); $sorter->sort(); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/Sorter/VertexTest.php000066400000000000000000000011441361230416200326400ustar00rootroot00000000000000value); self::assertSame(Vertex::NOT_VISITED, $node->state); self::assertEmpty($node->dependencyList); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/000077500000000000000000000000001361230416200311525ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestDocument/Role.php000066400000000000000000000011271361230416200325650ustar00rootroot00000000000000id; } public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/000077500000000000000000000000001361230416200306505ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Group.php000066400000000000000000000013001361230416200324470ustar00rootroot00000000000000id = $id; } public function getId() : ?int { return $this->id; } public function setCode($code) : void { $this->code = $code; } public function getCode() : ?string { return $this->code; } } GroupWithSchema.php000066400000000000000000000013731361230416200343570ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntityid = $id; } public function getId() : ?int { return $this->id; } public function setCode($code) : void { $this->code = $code; } public function getCode() : ?string { return $this->code; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Link.php000066400000000000000000000013061361230416200322560ustar00rootroot00000000000000id = $id; } public function getId() { return $this->id; } public function getUrl() { return $this->url; } public function setUrl($url) { $this->url = $url; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Quoted.php000066400000000000000000000027361361230416200326320ustar00rootroot00000000000000id; } public function setId(?int $id) : void { $this->id = $id; } public function getSelect() : ?string { return $this->select; } public function setSelect(?string $select) : void { $this->select = $select; } /** * @return Collection|null */ public function getSelects() : ?Collection { return $this->selects; } /** * @param Collection|null $selects */ public function setSelects(?Collection $selects) : void { $this->selects = $selects; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/Role.php000066400000000000000000000011721361230416200322630ustar00rootroot00000000000000id; } public function setName($name) { $this->name = $name; } public function getName() { return $this->name; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntity/User.php000066400000000000000000000053041361230416200323010ustar00rootroot00000000000000id = $id; } public function getId() : ?int { return $this->id; } public function setCode($code) { $this->code = $code; } public function getCode() : ?string { return $this->code; } public function setPassword($password) { $this->password = md5($password); } public function getPassword() { return $this->password; } public function setEmail($email) { $this->email = $email; } public function getEmail() { return $this->email; } public function setRole(Role $role) { $this->role = $role; } public function getRole() { return $this->role; } /** * @return User[]|Collection */ public function getReaders() { return $this->readers; } /** * @param User[]|Collection $readers * * @return User */ public function setReaders($readers) { $this->readers = $readers; return $this; } /** * @return User[]|Collection */ public function getAuthors() { return $this->authors; } /** * @param User[]|Collection $authors * * @return User */ public function setAuthors($authors) { $this->authors = $authors; return $this; } } UserWithSchema.php000066400000000000000000000055421361230416200342030ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestEntityid = $id; } public function getId() : ?int { return $this->id; } public function setCode($code) { $this->code = $code; } public function getCode() : ?string { return $this->code; } public function setPassword($password) { $this->password = md5($password); } public function getPassword() { return $this->password; } public function setEmail($email) { $this->email = $email; } public function getEmail() { return $this->email; } public function setRole(Role $role) { $this->role = $role; } public function getRole() { return $this->role; } /** * @return UserWithSchema[]|Collection */ public function getReaders() { return $this->readers; } /** * @param UserWithSchema[]|Collection $readers * * @return UserWithSchema */ public function setReaders($readers) { $this->readers = $readers; return $this; } /** * @return UserWithSchema[]|Collection */ public function getAuthors() { return $this->authors; } /** * @param UserWithSchema[]|Collection $authors * * @return UserWithSchema */ public function setAuthors($authors) { $this->authors = $authors; return $this; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestFixtures/000077500000000000000000000000001361230416200312055ustar00rootroot00000000000000MyFixture1.php000066400000000000000000000004041361230416200336520ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestFixturesreferenceRepository = $referenceRepository; } public function load(ObjectManager $manager) { $adminRole = new Role(); $adminRole->setName('admin'); $manager->persist($adminRole); $this->referenceRepository->addReference('admin-role', $adminRole); $manager->flush(); } } UserFixture.php000066400000000000000000000013111361230416200341200ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestFixturessetId(4); $admin->setCode('007'); $admin->setEmail('admin@example.com'); $admin->setPassword('secret'); $role = $this->getReference('admin-role'); $admin->setRole($role); $manager->persist($admin); $manager->flush(); $this->addReference('admin', $admin); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntity/000077500000000000000000000000001361230416200316535ustar00rootroot00000000000000ExcludedEntity.php000066400000000000000000000006441361230416200352430ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntityid = $id; } public function getId() { return $this->id; } } IncludedEntity.php000066400000000000000000000006441361230416200352350ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestPurgeEntityid = $id; } public function getId() { return $this->id; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestTypes/000077500000000000000000000000001361230416200305005ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestTypes/UuidType.php000066400000000000000000000016361361230416200327670ustar00rootroot00000000000000getVarcharTypeDeclarationSQL($field_declaration); } public function convertToPHPValue($value, AbstractPlatform $platform) { return $value === null ? null : new Uuid($value); } public function convertToDatabaseValue($value, AbstractPlatform $platform) { return $value === null ? null : (string) $value; } public function getName() { return self::NAME; } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestValueObjects/000077500000000000000000000000001361230416200317625ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Common/DataFixtures/TestValueObjects/Uuid.php000066400000000000000000000014451361230416200334050ustar00rootroot00000000000000id = $id; } public function getId() { return $this->id; } public function jsonSerialize() { return $this->id; } public function serialize() { return $this->id; } public function unserialize($serialized) { $this->id = $serialized; } public function __toString() { return $this->id; } public static function unknown() { return new self('00000000-0000-0000-C000-000000000046'); } } php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Mock/000077500000000000000000000000001361230416200235725ustar00rootroot00000000000000php-doctrine-data-fixtures-1.4.2/tests/Doctrine/Tests/Mock/Node.php000066400000000000000000000004111361230416200251640ustar00rootroot00000000000000value = $value; } }