|
7 | 7 | use Brainbits\FunctionalTestHelpers\Snapshot\SnapshotTrait; |
8 | 8 | use org\bovigo\vfs\vfsStream; |
9 | 9 | use org\bovigo\vfs\vfsStreamDirectory; |
| 10 | +use PHPUnit\Framework\AssertionFailedError; |
10 | 11 | use PHPUnit\Framework\ExpectationFailedException; |
11 | 12 | use PHPUnit\Framework\TestCase; |
12 | 13 |
|
| 14 | +use function getenv; |
13 | 15 | use function Safe\file_get_contents; |
14 | 16 | use function Safe\file_put_contents; |
| 17 | +use function Safe\putenv; |
15 | 18 |
|
16 | 19 | /** @covers \Brainbits\FunctionalTestHelpers\Snapshot\SnapshotTrait */ |
17 | 20 | final class JsonLdSnapshotTest extends TestCase |
@@ -199,6 +202,70 @@ public function testNamedJsonLdAssertionFails(): void |
199 | 202 | $this->fail('Assertion did not fail'); |
200 | 203 | } |
201 | 204 |
|
| 205 | + public function testSnapshotsAreNotCreatedForCreateSnapshotFalse(): void |
| 206 | + { |
| 207 | + $data = '<foo><bar>1</bar><baz>test</baz></foo>'; |
| 208 | + |
| 209 | + $prior = getenv('CREATE_SNAPSHOTS'); |
| 210 | + putenv('CREATE_SNAPSHOTS=false'); |
| 211 | + |
| 212 | + $thrownException = null; |
| 213 | + |
| 214 | + try { |
| 215 | + $this->assertMatchesXmlSnapshot($data); |
| 216 | + } catch (AssertionFailedError $e) { |
| 217 | + $thrownException = $e; |
| 218 | + } finally { |
| 219 | + putenv('CREATE_SNAPSHOTS=' . $prior); |
| 220 | + } |
| 221 | + |
| 222 | + $this->assertInstanceOf(AssertionFailedError::class, $thrownException, 'Snapshot test did not fail.'); |
| 223 | + $this->assertSame( |
| 224 | + 'Snapshot json_ld_snapshot_snapshots_are_not_created_for_create_snapshot_false.xml does not exist.', |
| 225 | + $thrownException->getMessage(), |
| 226 | + ); |
| 227 | + } |
| 228 | + |
| 229 | + public function testSnapshotsAreNotCreatedForCreateSnapshotZero(): void |
| 230 | + { |
| 231 | + $data = '<foo><bar>1</bar><baz>test</baz></foo>'; |
| 232 | + |
| 233 | + $prior = getenv('CREATE_SNAPSHOTS'); |
| 234 | + putenv('CREATE_SNAPSHOTS=0'); |
| 235 | + |
| 236 | + $thrownException = null; |
| 237 | + |
| 238 | + try { |
| 239 | + $this->assertMatchesXmlSnapshot($data); |
| 240 | + } catch (AssertionFailedError $e) { |
| 241 | + $thrownException = $e; |
| 242 | + } finally { |
| 243 | + putenv('CREATE_SNAPSHOTS=' . $prior); |
| 244 | + } |
| 245 | + |
| 246 | + $this->assertInstanceOf(AssertionFailedError::class, $thrownException, 'Snapshot test did not fail.'); |
| 247 | + $this->assertSame( |
| 248 | + 'Snapshot json_ld_snapshot_snapshots_are_not_created_for_create_snapshot_zero.xml does not exist.', |
| 249 | + $thrownException->getMessage(), |
| 250 | + ); |
| 251 | + } |
| 252 | + |
| 253 | + public function testCreateSnapshotEnvIsNotProcessedForOtherValue(): void |
| 254 | + { |
| 255 | + $data = '<foo><bar>1</bar><baz>test</baz></foo>'; |
| 256 | + |
| 257 | + $prior = getenv('CREATE_SNAPSHOTS'); |
| 258 | + putenv('CREATE_SNAPSHOTS=true'); |
| 259 | + |
| 260 | + try { |
| 261 | + $this->assertMatchesXmlSnapshot($data); |
| 262 | + } catch (AssertionFailedError) { |
| 263 | + $this->fail('Unexpected fail() was called'); |
| 264 | + } finally { |
| 265 | + putenv('CREATE_SNAPSHOTS=' . $prior); |
| 266 | + } |
| 267 | + } |
| 268 | + |
202 | 269 | /** |
203 | 270 | * Overwrite function in using class to locate __snapshot__ directory correctly. |
204 | 271 | */ |
|
0 commit comments