diff --git a/composer.json b/composer.json index 3de6aa55ce..7303a15589 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,7 @@ "autoload": { "psr-4": { "Faker\\": "src/Faker/" - }, - "files": [ - "src/Faker/ORM/Doctrine/backward-compatibility.php" - ] + } }, "autoload-dev": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index d302ac8fcd..d23694b6cb 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,6 +3,8 @@ includes: parameters: level: 5 + bootstrapFiles: + - src/Faker/ORM/Doctrine/backward-compatibility.php paths: - src tmpDir: .build/phpstan/ diff --git a/src/Faker/ORM/Doctrine/ColumnTypeGuesser.php b/src/Faker/ORM/Doctrine/ColumnTypeGuesser.php index 0672d1d7d3..3267fe469b 100644 --- a/src/Faker/ORM/Doctrine/ColumnTypeGuesser.php +++ b/src/Faker/ORM/Doctrine/ColumnTypeGuesser.php @@ -5,6 +5,8 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Faker\Generator; +require_once 'backward-compatibility.php'; + class ColumnTypeGuesser { protected $generator; diff --git a/src/Faker/ORM/Doctrine/EntityPopulator.php b/src/Faker/ORM/Doctrine/EntityPopulator.php index 8bd8bede66..79d3796b8a 100644 --- a/src/Faker/ORM/Doctrine/EntityPopulator.php +++ b/src/Faker/ORM/Doctrine/EntityPopulator.php @@ -5,6 +5,8 @@ use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Persistence\ObjectManager; +require_once 'backward-compatibility.php'; + /** * Service class for populating a table through a Doctrine Entity class. */ diff --git a/src/Faker/ORM/Doctrine/Populator.php b/src/Faker/ORM/Doctrine/Populator.php index a1284edac3..893d856627 100644 --- a/src/Faker/ORM/Doctrine/Populator.php +++ b/src/Faker/ORM/Doctrine/Populator.php @@ -5,6 +5,8 @@ use Doctrine\Common\Persistence\ObjectManager; use Faker\Generator; +require_once 'backward-compatibility.php'; + /** * Service class for populating a database using the Doctrine ORM or ODM. * A Populator can populate several tables using ActiveRecord classes. diff --git a/test/Faker/ORM/Doctrine/ColumnTypeGuesserTest.php b/test/Faker/ORM/Doctrine/ColumnTypeGuesserTest.php new file mode 100644 index 0000000000..5b105793b2 --- /dev/null +++ b/test/Faker/ORM/Doctrine/ColumnTypeGuesserTest.php @@ -0,0 +1,25 @@ +faker); + // Mock ClassMetadata after autoload to test class alias + $classMetaData = $this->createMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); + $classMetaData->method('getTypeOfField')->with(self::anything())->willReturn('integer'); + + $fakerClosure = $columnTypeGuesser->guessFormat('test', $classMetaData); + self::assertIsNumeric($fakerClosure()); + } +} diff --git a/test/Faker/ORM/Doctrine/EntityPopulatorTest.php b/test/Faker/ORM/Doctrine/EntityPopulatorTest.php new file mode 100644 index 0000000000..a538785f59 --- /dev/null +++ b/test/Faker/ORM/Doctrine/EntityPopulatorTest.php @@ -0,0 +1,26 @@ +createMock('Doctrine\Common\Persistence\Mapping\ClassMetadata'); + $classMetaData->method('getName')->willReturn('test'); + $entityPopulator = new EntityPopulator($classMetaData); + + self::assertSame('test', $entityPopulator->getClass()); + } +} diff --git a/test/Faker/ORM/Doctrine/PopulatorTest.php b/test/Faker/ORM/Doctrine/PopulatorTest.php new file mode 100644 index 0000000000..34bfb4d8fa --- /dev/null +++ b/test/Faker/ORM/Doctrine/PopulatorTest.php @@ -0,0 +1,23 @@ +faker); + // Mock ObjectManager after autoload to test class alias + $objectManager = $this->createMock('Doctrine\Common\Persistence\ObjectManager'); + + self::assertEmpty($populator->execute($objectManager)); + } +}