|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest; |
|
6
|
|
|
|
|
7
|
|
|
class FileCreationTransactionIntegrationTest extends AbstractIntegrationTest |
|
8
|
|
|
{ |
|
9
|
|
|
public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/FileCreationTransactionTest/'; |
|
10
|
|
|
public const TEST_PATH_1 = self::WORK_DIR.'1.txt'; |
|
11
|
|
|
public const TEST_PATH_2 = self::WORK_DIR.'2.txt'; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
15
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
16
|
|
|
*/ |
|
17
|
|
|
public function setup() |
|
18
|
|
|
{ |
|
19
|
|
|
parent::setup(); |
|
20
|
|
|
FileCreationTransaction::markTransactionSuccessful(); |
|
21
|
|
|
foreach ([self::TEST_PATH_1, self::TEST_PATH_2] as $path) { |
|
22
|
|
|
file_put_contents($path, $path); |
|
23
|
|
|
FileCreationTransaction::setPathCreated($path); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testCanAddFile() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertCount(2, FileCreationTransaction::getTransaction()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
|
37
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testPathsDeduplicated() |
|
40
|
|
|
{ |
|
41
|
|
|
FileCreationTransaction::setPathCreated(self::TEST_PATH_1); |
|
42
|
|
|
$this->assertCount(2, FileCreationTransaction::getTransaction()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testCanEchoFindCommands() |
|
48
|
|
|
{ |
|
49
|
|
|
$output = $this->getFindCommands(); |
|
50
|
|
|
$this->assertNotEmpty($output); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string |
|
55
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function getFindCommands(): string |
|
58
|
|
|
{ |
|
59
|
|
|
$handle = fopen('php://memory', 'rwb'); |
|
60
|
|
|
FileCreationTransaction::echoDirtyTransactionCleanupCommands($handle); |
|
61
|
|
|
rewind($handle); |
|
|
|
|
|
|
62
|
|
|
$output = stream_get_contents($handle); |
|
|
|
|
|
|
63
|
|
|
fclose($handle); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
return (string)$output; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @SuppressWarnings(PHPMD.StaticAccess) |
|
70
|
|
|
*/ |
|
71
|
|
|
public function testMarkSuccessfulClearsTransaction() |
|
72
|
|
|
{ |
|
73
|
|
|
FileCreationTransaction::markTransactionSuccessful(); |
|
74
|
|
|
$output = $this->getFindCommands(); |
|
75
|
|
|
$this->assertEmpty($output); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|