1
|
|
|
<?php |
2
|
|
|
namespace Mathielen\ImportEngine; |
3
|
|
|
|
4
|
|
|
use Mathielen\ImportEngine\Import\Import; |
5
|
|
|
use Mathielen\ImportEngine\Import\Run\ImportRunner; |
6
|
|
|
use Mathielen\ImportEngine\Importer\Importer; |
7
|
|
|
use Mathielen\ImportEngine\Storage\ArrayStorage; |
8
|
|
|
use Mathielen\ImportEngine\Validation\ValidatorValidation; |
9
|
|
|
use Symfony\Component\Validator\Constraints\Choice; |
10
|
|
|
use Symfony\Component\Validator\Validation; |
11
|
|
|
|
12
|
|
|
class MultiImportValidationResetTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @medium |
17
|
|
|
*/ |
18
|
|
|
public function test() |
19
|
|
|
{ |
20
|
|
|
$data1 = [['foo' => 'bar1']]; |
21
|
|
|
$data2 = [['foo' => 'bar2']]; |
22
|
|
|
|
23
|
|
|
$targetData = array(); |
24
|
|
|
$targetStorage = new ArrayStorage($targetData); |
25
|
|
|
|
26
|
|
|
$validator = Validation::createValidator(); |
27
|
|
|
$validation = new ValidatorValidation($validator); |
28
|
|
|
$validation->addSourceConstraint('foo', new Choice(['choices'=>['a']])); |
29
|
|
|
|
30
|
|
|
$importer = Importer::build($targetStorage); |
31
|
|
|
$importer->validation($validation); |
32
|
|
|
|
33
|
|
|
$importRunner = ImportRunner::build(); |
34
|
|
|
|
35
|
|
|
$import = Import::build($importer, new ArrayStorage($data1)); |
36
|
|
|
$importRunner->dryRun($import); |
37
|
|
|
$this->assertEquals(1, count($importer->validation()->getViolations()['source'])); |
38
|
|
|
|
39
|
|
|
$import = Import::build($importer, new ArrayStorage($data2)); |
40
|
|
|
$importRunner->dryRun($import); |
41
|
|
|
$this->assertEquals(1, count($importer->validation()->getViolations()['source'])); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
} |
45
|
|
|
|