|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | 5 | use Ibexa\Contracts\Core\Repository\Events\Content\BeforeDeleteContentEvent; |
6 | | -use Ibexa\Contracts\Core\Repository\Events\Content\CreateContentEvent; |
7 | | -use Ibexa\Contracts\Core\Repository\Events\Content\UpdateContentEvent; |
| 6 | +use Ibexa\Contracts\Core\Repository\Events\Content\PublishVersionEvent; |
8 | 7 | use Ibexa\Contracts\Core\Repository\Values\Content\Content; |
9 | | -use Ibexa\Contracts\Core\Repository\Values\Content\ContentCreateStruct; |
10 | 8 | use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; |
11 | | -use Ibexa\Contracts\Core\Repository\Values\Content\ContentUpdateStruct; |
12 | 9 | use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; |
13 | 10 | use Psr\Log\NullLogger; |
14 | 11 | use vardumper\IbexaAutomaticMigrationsBundle\EventListener\ContentListener; |
|
31 | 28 | 'contentInfo' => $contentInfo, |
32 | 29 | default => null, |
33 | 30 | }); |
34 | | - $createStruct = $this->createStub(ContentCreateStruct::class); |
35 | | - $versionInfo = $this->createStub(VersionInfo::class); |
36 | | - $updateStruct = $this->createStub(ContentUpdateStruct::class); |
37 | 31 |
|
38 | | - $this->createEvent = new CreateContentEvent($content, $createStruct, [], null); |
39 | | - $this->updateEvent = new UpdateContentEvent($content, $versionInfo, $updateStruct, null); |
| 32 | + $versionInfoV1 = $this->getMockBuilder(VersionInfo::class) |
| 33 | + ->disableOriginalConstructor() |
| 34 | + ->getMock(); |
| 35 | + $versionInfoV1->method('getVersionNo')->willReturn(1); |
| 36 | + |
| 37 | + $versionInfoV2 = $this->getMockBuilder(VersionInfo::class) |
| 38 | + ->disableOriginalConstructor() |
| 39 | + ->getMock(); |
| 40 | + $versionInfoV2->method('getVersionNo')->willReturn(2); |
| 41 | + |
| 42 | + $this->publishCreateEvent = new PublishVersionEvent($content, $versionInfoV1, []); |
| 43 | + $this->publishUpdateEvent = new PublishVersionEvent($content, $versionInfoV2, []); |
40 | 44 | $this->deleteEvent = new BeforeDeleteContentEvent($contentInfo); |
41 | 45 | }); |
42 | 46 |
|
|
49 | 53 | expect(is_dir($this->tmpDir . '/src/MigrationsDefinitions'))->toBeTrue(); |
50 | 54 | }); |
51 | 55 |
|
52 | | - it('onCreated returns early when not enabled (APP_ENV=testing)', function () { |
| 56 | + it('onPublished (create) returns early when not enabled (APP_ENV=testing)', function () { |
53 | 57 | // SettingsService::isEnabled() returns false when APP_ENV != 'dev' |
54 | | - expect(fn () => $this->listener->onCreated($this->createEvent))->not->toThrow(\Throwable::class); |
| 58 | + expect(fn () => $this->listener->onPublished($this->publishCreateEvent))->not->toThrow(\Throwable::class); |
55 | 59 | }); |
56 | 60 |
|
57 | | - it('onUpdated returns early when not enabled', function () { |
58 | | - expect(fn () => $this->listener->onUpdated($this->updateEvent))->not->toThrow(\Throwable::class); |
| 61 | + it('onPublished (update) returns early when not enabled', function () { |
| 62 | + expect(fn () => $this->listener->onPublished($this->publishUpdateEvent))->not->toThrow(\Throwable::class); |
59 | 63 | }); |
60 | 64 |
|
61 | 65 | it('onBeforeDeleted returns early when not enabled', function () { |
62 | 66 | expect(fn () => $this->listener->onBeforeDeleted($this->deleteEvent))->not->toThrow(\Throwable::class); |
63 | 67 | }); |
64 | 68 |
|
65 | | - it('onCreated returns early when content type disabled in dev env', function () { |
| 69 | + it('onPublished returns early when content type disabled in dev env', function () { |
66 | 70 | $previous = $_SERVER['APP_ENV'] ?? null; |
67 | 71 | $_SERVER['APP_ENV'] = 'dev'; |
68 | 72 | try { |
|
71 | 75 | makeSettingsService($this->tmpDir, true, ['content' => false]), |
72 | 76 | $this->tmpDir |
73 | 77 | ); |
74 | | - expect(fn () => $listener->onCreated($this->createEvent))->not->toThrow(\Throwable::class); |
| 78 | + expect(fn () => $listener->onPublished($this->publishCreateEvent))->not->toThrow(\Throwable::class); |
75 | 79 | } finally { |
76 | 80 | if ($previous === null) { |
77 | 81 | unset($_SERVER['APP_ENV']); |
|
81 | 85 | } |
82 | 86 | }); |
83 | 87 |
|
84 | | - it('onCreated reaches generateMigration in dev env', function () { |
85 | | - withEnv('dev', fn () => expect(fn () => $this->listener->onCreated($this->createEvent))->not->toThrow(\Throwable::class)); |
| 88 | + it('onPublished (create) reaches generateMigration in dev env', function () { |
| 89 | + withEnv('dev', fn () => expect(fn () => $this->listener->onPublished($this->publishCreateEvent))->not->toThrow(\Throwable::class)); |
86 | 90 | }); |
87 | 91 |
|
88 | | - it('onUpdated reaches generateMigration in dev env', function () { |
89 | | - withEnv('dev', fn () => expect(fn () => $this->listener->onUpdated($this->updateEvent))->not->toThrow(\Throwable::class)); |
| 92 | + it('onPublished (update) reaches generateMigration in dev env', function () { |
| 93 | + withEnv('dev', fn () => expect(fn () => $this->listener->onPublished($this->publishUpdateEvent))->not->toThrow(\Throwable::class)); |
90 | 94 | }); |
91 | 95 |
|
92 | 96 | it('onBeforeDeleted reaches generateMigration in dev env', function () { |
|
105 | 109 | 'contentInfo' => $contentInfo, |
106 | 110 | default => null, |
107 | 111 | }); |
108 | | - $createStruct = $this->createStub(ContentCreateStruct::class); |
109 | | - $versionInfo = $this->createStub(VersionInfo::class); |
110 | | - $updateStruct = $this->createStub(ContentUpdateStruct::class); |
111 | 112 |
|
112 | | - $this->createEvent = new CreateContentEvent($content, $createStruct, [], null); |
113 | | - $this->updateEvent = new UpdateContentEvent($content, $versionInfo, $updateStruct, null); |
| 113 | + $versionInfoV1 = $this->getMockBuilder(VersionInfo::class) |
| 114 | + ->disableOriginalConstructor() |
| 115 | + ->getMock(); |
| 116 | + $versionInfoV1->method('getVersionNo')->willReturn(1); |
| 117 | + |
| 118 | + $versionInfoV2 = $this->getMockBuilder(VersionInfo::class) |
| 119 | + ->disableOriginalConstructor() |
| 120 | + ->getMock(); |
| 121 | + $versionInfoV2->method('getVersionNo')->willReturn(2); |
| 122 | + |
| 123 | + $this->publishCreateEvent = new PublishVersionEvent($content, $versionInfoV1, []); |
| 124 | + $this->publishUpdateEvent = new PublishVersionEvent($content, $versionInfoV2, []); |
114 | 125 | $this->deleteEvent = new BeforeDeleteContentEvent($contentInfo); |
115 | 126 | }); |
116 | 127 |
|
117 | 128 | afterEach(function () { |
118 | 129 | removeTmpDir($this->tmpDir); |
119 | 130 | }); |
120 | 131 |
|
121 | | - it('onCreated handles successful runner branch', function () { |
| 132 | + it('onPublished (create) handles successful runner branch', function () { |
122 | 133 | $listener = withTestingEnv(fn () => new ContentListener( |
123 | 134 | new NullLogger(), |
124 | 135 | makeSettingsService($this->tmpDir, true, ['content' => true]), |
125 | 136 | $this->tmpDir, |
126 | 137 | makeFakeRunner(0) |
127 | 138 | )); |
128 | 139 |
|
129 | | - withEnv('dev', fn () => expect(fn () => $listener->onCreated($this->createEvent))->not->toThrow(\Throwable::class)); |
| 140 | + withEnv('dev', fn () => expect(fn () => $listener->onPublished($this->publishCreateEvent))->not->toThrow(\Throwable::class)); |
130 | 141 | }); |
131 | 142 |
|
132 | | - it('onUpdated handles failed runner branch', function () { |
| 143 | + it('onPublished (update) handles failed runner branch', function () { |
133 | 144 | $listener = withTestingEnv(fn () => new ContentListener( |
134 | 145 | new NullLogger(), |
135 | 146 | makeSettingsService($this->tmpDir, true, ['content' => true]), |
136 | 147 | $this->tmpDir, |
137 | 148 | makeFakeRunner(1, '', 'boom') |
138 | 149 | )); |
139 | 150 |
|
140 | | - withEnv('dev', fn () => expect(fn () => $listener->onUpdated($this->updateEvent))->not->toThrow(\Throwable::class)); |
| 151 | + withEnv('dev', fn () => expect(fn () => $listener->onPublished($this->publishUpdateEvent))->not->toThrow(\Throwable::class)); |
141 | 152 | }); |
142 | 153 |
|
143 | | - it('onCreated – forced ibexa mode – exercises ibexa generation branch', function () { |
| 154 | + it('onPublished (create) – forced ibexa mode – exercises ibexa generation branch', function () { |
144 | 155 | $listener = withTestingEnv(fn () => new ContentListener( |
145 | 156 | new NullLogger(), |
146 | 157 | makeSettingsService($this->tmpDir, true, ['content' => true]), |
|
149 | 160 | )); |
150 | 161 | setPrivateProperty($listener, 'mode', 'ibexa'); |
151 | 162 |
|
152 | | - withEnv('dev', fn () => expect(fn () => $listener->onCreated($this->createEvent))->not->toThrow(\Throwable::class)); |
| 163 | + withEnv('dev', fn () => expect(fn () => $listener->onPublished($this->publishCreateEvent))->not->toThrow(\Throwable::class)); |
153 | 164 | }); |
154 | 165 | }); |
0 commit comments