|
1
|
|
|
<?php |
|
2
|
|
|
namespace Mathielen\ImportEngine; |
|
3
|
|
|
|
|
4
|
|
|
class ReadmeTest extends \PHPUnit_Framework_TestCase |
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @dataProvider parseReadme |
|
9
|
|
|
*/ |
|
10
|
|
|
public function testPhpCode($startLine, $code) |
|
11
|
|
|
{ |
|
12
|
|
|
if (strpos($code, '...')) { |
|
13
|
|
|
$this->markTestSkipped("Cannot test with insufficient info."); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
ob_start(); |
|
17
|
|
|
eval($code); |
|
18
|
|
|
$output = ob_get_contents(); |
|
19
|
|
|
ob_end_clean(); |
|
20
|
|
|
|
|
21
|
|
|
if (!empty($output)) { |
|
22
|
|
|
$this->fail("Error in README.me at line $startLine:\n".$output); |
|
23
|
|
|
} |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function parseReadme() |
|
27
|
|
|
{ |
|
28
|
|
|
$chunks = array(); |
|
29
|
|
|
$readme = file(__DIR__ . '/../../../../README.md'); |
|
30
|
|
|
|
|
31
|
|
|
$startLine = $endLine = null; |
|
32
|
|
|
$i = 0; |
|
33
|
|
|
foreach ($readme as $line) { |
|
34
|
|
|
if ('```php' == trim($line)) { |
|
35
|
|
|
$startLine = $i; |
|
36
|
|
|
$endLine = null; |
|
37
|
|
|
} elseif ('```' == trim($line)) { |
|
38
|
|
|
$endLine = $i; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($startLine && $endLine) { |
|
|
|
|
|
|
42
|
|
|
$startLine++; |
|
43
|
|
|
$code = join('', array_slice($readme, $startLine, $endLine-$startLine)); |
|
44
|
|
|
|
|
45
|
|
|
$code = str_replace('$ffsp = ...', $this->getBuildFFSP(), $code); |
|
46
|
|
|
$code = str_replace('$targetStorage = ...', $this->getBuildTargetStorage(), $code); |
|
47
|
|
|
$code = str_replace('$importRunner = ...', $this->getBuildImportRunnerCode(), $code); |
|
48
|
|
|
$code = str_replace('$importRun = ...', $this->getBuildImportRunCode(), $code); |
|
49
|
|
|
$code = str_replace('$importer = ...', $this->getBuildImporterCode(), $code); |
|
50
|
|
|
$code = str_replace('$import = ...', $this->getBuildImportCode(), $code); |
|
51
|
|
|
$code = str_replace('$validator = ...', $this->getBuildValidatorCode(), $code); |
|
52
|
|
|
$code = str_replace('$validation = ...', $this->getBuildValidationCode(), $code); |
|
53
|
|
|
$code = str_replace('$jms_serializer = ...', $this->getBuildJmsSerializerCode(), $code); |
|
54
|
|
|
|
|
55
|
|
|
$chunks[] = array($startLine, $code); |
|
56
|
|
|
$startLine = $endLine = null; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
++$i; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $chunks; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function getBuildValidationCode() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getBuildValidatorCode() . ' |
|
68
|
|
|
$validation = new Mathielen\ImportEngine\Validation\ValidatorValidation($validator); |
|
69
|
|
|
'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function getBuildValidatorCode() |
|
73
|
|
|
{ |
|
74
|
|
|
return ' |
|
75
|
|
|
$validator = $this->createMock("Symfony\Component\Validator\Validator\ValidatorInterface"); |
|
76
|
|
|
'; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
private function getBuildJmsSerializerCode() |
|
80
|
|
|
{ |
|
81
|
|
|
return ' |
|
82
|
|
|
$jms_serializer = $this->createMock("JMS\Serializer\Serializer", array(), array(), "", false); |
|
83
|
|
|
'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
private function getBuildImportRunnerCode() |
|
87
|
|
|
{ |
|
88
|
|
|
return ' |
|
89
|
|
|
$importRunner = new Mathielen\ImportEngine\Import\Run\ImportRunner(new Mathielen\ImportEngine\Import\Workflow\DefaultWorkflowFactory(new Symfony\Component\EventDispatcher\EventDispatcher())); |
|
90
|
|
|
'; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
private function getBuildImportRunCode() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->getBuildImportCode() . ' |
|
96
|
|
|
$importConfiguration = new Mathielen\ImportEngine\ValueObject\ImportConfiguration(); |
|
97
|
|
|
$importRun = $importConfiguration->toRun(); |
|
98
|
|
|
'; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
private function getBuildImportCode() |
|
102
|
|
|
{ |
|
103
|
|
|
return $this->getBuildImporterCode() . ' |
|
104
|
|
|
$a = array(array("field1"=>"data1")); |
|
105
|
|
|
$import = Mathielen\ImportEngine\Import\Import::build($importer, new Mathielen\ImportEngine\Storage\ArrayStorage($a)); |
|
106
|
|
|
'; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
private function getBuildImporterCode() |
|
110
|
|
|
{ |
|
111
|
|
|
return |
|
112
|
|
|
$this->getBuildValidationCode() . |
|
113
|
|
|
$this->getBuildFFSP() . |
|
114
|
|
|
$this->getBuildTargetStorage() . ' |
|
115
|
|
|
$importer = Mathielen\ImportEngine\Importer\Importer::build($targetStorage); |
|
116
|
|
|
$importer->validation($validation); |
|
117
|
|
|
'; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
private function getBuildTargetStorage() |
|
121
|
|
|
{ |
|
122
|
|
|
return ' |
|
123
|
|
|
$a = array(); |
|
124
|
|
|
$targetStorage = new Mathielen\ImportEngine\Storage\ArrayStorage($a); |
|
125
|
|
|
'; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
private function getBuildFFSP() |
|
129
|
|
|
{ |
|
130
|
|
|
return ' |
|
131
|
|
|
$ffsp = new Mathielen\ImportEngine\Storage\Provider\FinderFileStorageProvider(Symfony\Component\Finder\Finder::create()); |
|
132
|
|
|
'; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: