1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
<?php
namespace League\Csv\Test\Plugin;
use League\Csv\Plugin\ColumnConsistencyValidator;
use League\Csv\Test\AbstractTestCase;
use League\Csv\Writer;
use SplFileObject;
use SplTempFileObject;
/**
* @group validators
*/
class ColumnConsistencyValidatorTest extends AbstractTestCase
{
private $csv;
public function setUp()
{
$this->csv = Writer::createFromFileObject(new SplTempFileObject());
}
public function tearDown()
{
$csv = new SplFileObject(dirname(__DIR__).'/data/foo.csv', 'w');
$csv->setCsvControl();
$csv->fputcsv(['john', 'doe', 'john.doe@example.com'], ',', '"');
$this->csv = null;
}
/**
* @expectedException InvalidArgumentException
*/
public function testColumsCountSetterGetter()
{
$consistency = new ColumnConsistencyValidator();
$this->assertSame(-1, $consistency->getColumnsCount());
$consistency->setColumnsCount(3);
$this->assertSame(3, $consistency->getColumnsCount());
$consistency->setColumnsCount('toto');
}
/**
* @expectedException InvalidArgumentException
*/
public function testColumsCountConsistency()
{
$consistency = new ColumnConsistencyValidator();
$this->csv->addValidator($consistency, 'consistency');
$this->csv->insertOne(['john', 'doe', 'john.doe@example.com']);
$consistency->setColumnsCount(2);
$this->csv->insertOne(['jane', 'jane.doe@example.com']);
$consistency->setColumnsCount(3);
$this->csv->insertOne(['jane', 'jane.doe@example.com']);
}
/**
* @expectedException InvalidArgumentException
*/
public function testAutoDetectColumnsCount()
{
$consistency = new ColumnConsistencyValidator();
$this->csv->addValidator($consistency, 'consistency');
$consistency->autodetectColumnsCount();
$this->assertSame(-1, $consistency->getColumnsCount());
$this->csv->insertOne(['john', 'doe', 'john.doe@example.com']);
$this->assertSame(3, $consistency->getColumnsCount());
$this->csv->insertOne(['jane', 'jane.doe@example.com']);
}
}
|