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
15 changed files
with
342 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
26 changes: 26 additions & 0 deletions
26
tests/Fixture/ForceFactoriesTraitUsage/KernelTestCaseWithOnlyResetDatabaseTraitTest.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,26 @@ | ||
<?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\ResetDatabase; | ||
|
||
final class KernelTestCaseWithOnlyResetDatabaseTraitTest extends KernelTestCase | ||
{ | ||
use ResetDatabase; | ||
|
||
public function test_using_foundry_without_trait_should_throw(): void | ||
{ | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Integration/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,46 @@ | ||
<?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 Integration\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; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw_even_when_kernel_is_booted(): void | ||
{ | ||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Integration/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,46 @@ | ||
<?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 Integration\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; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw_even_when_kernel_is_booted(): void | ||
{ | ||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithFactoriesTraitTest.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,45 @@ | ||
<?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 Integration\ForceFactoriesTraitUsage; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class KernelTestCaseWithFactoriesTraitTest extends KernelTestCase | ||
{ | ||
use Factories; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw_even_when_kernel_is_booted(): void | ||
{ | ||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
tests/Integration/ForceFactoriesTraitUsage/KernelTestCaseWithoutFactoriesTraitTest.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,44 @@ | ||
<?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 Integration\ForceFactoriesTraitUsage; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Foundry\Exception\FoundryNotBooted; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class KernelTestCaseWithoutFactoriesTraitTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function using_foundry_without_trait_should_throw(): void | ||
{ | ||
$this->expectException(FoundryNotBooted::class); | ||
|
||
Object1Factory::createOne(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function using_foundry_without_trait_should_throw_even_when_kernel_is_booted(): void | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('You must use the trait "Zenstruck\Foundry\Test\Factories"'); | ||
|
||
self::getContainer(); | ||
|
||
Object1Factory::createOne(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/Integration/ForceFactoriesTraitUsage/UnitTestCaseWithFactoriesTraitTest.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,33 @@ | ||
<?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 Integration\ForceFactoriesTraitUsage; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class UnitTestCaseWithFactoriesTraitTest extends TestCase | ||
{ | ||
use Factories; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_not_throw(): void | ||
{ | ||
Object1Factory::createOne(); | ||
|
||
$this->expectNotToPerformAssertions(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Integration/ForceFactoriesTraitUsage/UnitTestCaseWithoutFactoriesTraitTest.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,31 @@ | ||
<?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 Integration\ForceFactoriesTraitUsage; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Zenstruck\Foundry\Exception\FoundryNotBooted; | ||
use Zenstruck\Foundry\Tests\Fixture\Factories\Object1Factory; | ||
|
||
final class UnitTestCaseWithoutFactoriesTraitTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function should_throw(): void | ||
{ | ||
$this->expectException(FoundryNotBooted::class); | ||
|
||
Object1Factory::createOne(); | ||
} | ||
} |
Oops, something went wrong.