1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\Foundry\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; |
6
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
7
|
|
|
use Zenstruck\Foundry\Test\Factories; |
8
|
|
|
use Zenstruck\Foundry\Test\ResetDatabase; |
9
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Factories\PostFactory; |
10
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Stories\CategoryStory; |
11
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Stories\PostStory; |
12
|
|
|
use Zenstruck\Foundry\Tests\Fixtures\Stories\ServiceStory; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Kevin Bond <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class StoryTest extends KernelTestCase |
18
|
|
|
{ |
19
|
|
|
use ExpectDeprecationTrait, Factories, ResetDatabase; |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
if (false === \getenv('DATABASE_URL')) { |
24
|
|
|
self::markTestSkipped('doctrine/orm not enabled.'); |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @test |
30
|
|
|
*/ |
31
|
|
|
public function stories_are_only_loaded_once(): void |
32
|
|
|
{ |
33
|
|
|
PostFactory::assert()->empty(); |
34
|
|
|
|
35
|
|
|
PostStory::load(); |
36
|
|
|
PostStory::load(); |
37
|
|
|
PostStory::load(); |
38
|
|
|
|
39
|
|
|
PostFactory::assert()->count(4); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @test |
44
|
|
|
*/ |
45
|
|
|
public function can_access_managed_proxies_via_magic_call(): void |
46
|
|
|
{ |
47
|
|
|
$this->assertSame('php', CategoryStory::load()->php()->getName()); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @test |
52
|
|
|
*/ |
53
|
|
|
public function can_access_managed_proxies_via_magic_call_static(): void |
54
|
|
|
{ |
55
|
|
|
$this->assertSame('php', CategoryStory::php()->getName()); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
*/ |
61
|
|
|
public function cannot_access_invalid_object(): void |
62
|
|
|
{ |
63
|
|
|
$this->expectException(\InvalidArgumentException::class); |
64
|
|
|
|
65
|
|
|
CategoryStory::load()->get('invalid'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @test |
70
|
|
|
*/ |
71
|
|
|
public function stories_can_be_services(): void |
72
|
|
|
{ |
73
|
|
|
if (!\getenv('USE_FOUNDRY_BUNDLE')) { |
74
|
|
|
$this->markTestSkipped('Stories cannot be services without the foundry bundle.'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$this->assertSame('From Service', ServiceStory::post()->getTitle()); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @test |
82
|
|
|
*/ |
83
|
|
|
public function service_stories_cannot_be_used_without_the_bundle(): void |
84
|
|
|
{ |
85
|
|
|
if (\getenv('USE_FOUNDRY_BUNDLE')) { |
86
|
|
|
$this->markTestSkipped('ZenstruckFoundryBundle enabled.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$this->expectException(\RuntimeException::class); |
90
|
|
|
$this->expectExceptionMessage('Stories with dependencies (Story services) cannot be used without the foundry bundle.'); |
91
|
|
|
|
92
|
|
|
ServiceStory::load(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @test |
97
|
|
|
* @group legacy |
98
|
|
|
*/ |
99
|
|
|
public function calling_add_is_deprecated(): void |
100
|
|
|
{ |
101
|
|
|
$this->expectDeprecation('Since zenstruck\foundry 1.17.0: Using Story::add() is deprecated, use Story::addState().'); |
102
|
|
|
|
103
|
|
|
CategoryStory::load()->add('foo', 'bar'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|