forked from zenstruck/foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throw an error if Factories trait is not used in a KernelTestCase
- Loading branch information
Showing
21 changed files
with
469 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/EndToEnd/ForceFactoriesTraitUsage/kernel_test_case_with_both_traits.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = '--filter'; | ||
$_SERVER['argv'][] = 'KernelTestCaseWithBothTraits'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
.... 4 / 4 (100%) | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
OK (4 tests, 4 assertions) |
23 changes: 23 additions & 0 deletions
23
tests/EndToEnd/ForceFactoriesTraitUsage/kernel_test_case_with_factory_trait.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithFactoriesTraitTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
.. 2 / 2 (100%) | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
OK (2 tests, 2 assertions) |
45 changes: 45 additions & 0 deletions
45
tests/EndToEnd/ForceFactoriesTraitUsage/kernel_test_case_without_factories_trait.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesTraitTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
EE 2 / 2 (100%) | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
There were 2 errors: | ||
|
||
1) Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\KernelTestCaseWithoutFactoriesTraitTest::test_using_foundry_without_trait_should_throw | ||
Zenstruck\Foundry\Exception\FoundryNotBooted: Foundry is not yet booted. Ensure ZenstruckFoundryBundle is enabled. If in a test, ensure your TestCase has the Factories trait. | ||
|
||
%s/src/Configuration.php:%d | ||
%s/src/ObjectFactory.php:%d | ||
%s/src/Factory.php:%d | ||
%s/tests/Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesTraitTest.php:%d | ||
|
||
2) Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\KernelTestCaseWithoutFactoriesTraitTest::test_using_foundry_without_trait_should_throw_even_when_kernel_is_booted | ||
LogicException: You must use the trait "Zenstruck\Foundry\Test\Factories" in "Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\KernelTestCaseWithoutFactoriesTraitTest" in order to use Foundry. | ||
|
||
%s/src/Configuration.php:%d | ||
%s/src/Configuration.php:%d | ||
%s/src/ZenstruckFoundryBundle.php:%d | ||
%s/vendor/symfony/http-kernel/Kernel.php:%d | ||
%s/vendor/symfony/framework-bundle/Test/KernelTestCase.php:%d | ||
%s/vendor/symfony/framework-bundle/Test/KernelTestCase.php:%d | ||
%s/tests/Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesTraitTest.php:%d | ||
|
||
ERRORS! | ||
Tests: 2, Assertions: 0, Errors: 2. |
38 changes: 38 additions & 0 deletions
38
...iesTraitUsage/kernel_test_case_without_factories_trait_but_with_reset_database_trait.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesButWithResetDatabaseTraitTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
E | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
There was 1 error: | ||
|
||
1) Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\KernelTestCaseWithoutFactoriesButWithResetDatabaseTraitTest | ||
LogicException: You must use the trait "Zenstruck\Foundry\Test\Factories" in "Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\KernelTestCaseWithoutFactoriesButWithResetDatabaseTraitTest" in order to use Foundry. | ||
|
||
%s/src/Configuration.php:%d | ||
%s/src/Configuration.php:%d | ||
%s/src/ZenstruckFoundryBundle.php:%d | ||
%s/vendor/symfony/http-kernel/Kernel.php:%d | ||
%s/vendor/symfony/framework-bundle/Test/KernelTestCase.php:%d | ||
%s/src/Test/ResetDatabase.php:%d | ||
%s/src/Persistence/ResetDatabase/ResetDatabaseManager.php:%d | ||
%s/src/Test/ResetDatabase.php:%d | ||
|
||
ERRORS! | ||
Tests: 1, Assertions: 0, Errors: 1. |
23 changes: 23 additions & 0 deletions
23
tests/EndToEnd/ForceFactoriesTraitUsage/unit_test_case_with_factories_trait.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/UnitTestCaseWithFactoriesTraitTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
. 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
OK (1 test, 1 assertion) |
35 changes: 35 additions & 0 deletions
35
tests/EndToEnd/ForceFactoriesTraitUsage/unit_test_case_without_factories_trait.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--TEST-- | ||
phpunit --version | ||
--FILE-- | ||
<?php | ||
$_ENV['KERNEL_CLASS'] = 'Zenstruck\Foundry\Tests\Fixture\TestKernel'; | ||
$_SERVER['argv'][] = '--do-not-cache-result'; | ||
$_SERVER['argv'][] = '--no-configuration'; | ||
$_SERVER['argv'][] = __DIR__ . '/../../Fixture/ForceFactoriesTraitUsage/UnitTestCaseWithoutFactoriesTraitTest.php'; | ||
|
||
require __DIR__ . '/../../bootstrap.php'; | ||
|
||
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']); | ||
?> | ||
--EXPECTF-- | ||
PHPUnit %s by Sebastian Bergmann and contributors. | ||
|
||
Runtime: PHP %s | ||
|
||
E 1 / 1 (100%) | ||
|
||
Time: %s, Memory: %s MB | ||
|
||
There was 1 error: | ||
|
||
1) Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage\UnitTestCaseWithoutFactoriesTraitTest::test_should_throw | ||
Zenstruck\Foundry\Exception\FoundryNotBooted: Foundry is not yet booted. Ensure ZenstruckFoundryBundle is enabled. If in a test, ensure your TestCase has the Factories trait. | ||
|
||
%s/src/Configuration.php:%d | ||
%s/src/ObjectFactory.php:%d | ||
%s/src/Factory.php:%d | ||
%s/tests/Fixture/ForceFactoriesTraitUsage/UnitTestCaseWithoutFactoriesTraitTest.php:%d | ||
|
||
ERRORS! | ||
Tests: 1, Assertions: 0, Errors: 1. | ||
|
40 changes: 40 additions & 0 deletions
40
tests/Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithBothTraitsInWrongOrderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the zenstruck/foundry package. | ||
* | ||
* (c) Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class KernelTestCaseWithBothTraitsInWrongOrderTest extends KernelTestCase | ||
{ | ||
use ResetDatabase, Factories; | ||
|
||
public function test_should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
self::assertTrue(true); | ||
} | ||
|
||
public function test_should_not_throw_even_when_kernel_is_booted(): void | ||
{ | ||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
|
||
self::assertTrue(true); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithBothTraitsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the zenstruck/foundry package. | ||
* | ||
* (c) Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Foundry\Tests\Fixture\ForceFactoriesTraitUsage; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class KernelTestCaseWithBothTraitsTest extends KernelTestCase | ||
{ | ||
use Factories, ResetDatabase; | ||
|
||
public function test_should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
self::assertTrue(true); | ||
} | ||
|
||
public function test_should_not_throw_even_when_kernel_is_booted(): void | ||
{ | ||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
|
||
self::assertTrue(true); | ||
} | ||
} |
Oops, something went wrong.