CsvParsingTest.php
1.17 KB
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
<?php
namespace tests\unit;
use common\components\UserStore;
use Yii;
class CsvParsingTest extends \Codeception\TestCase\Test
{
    /**
     * @var \UnitTester
     */
    protected $tester;
    private $options;
    private $file_path;
    private $data;
    public function _before()
    {
        $this->data = [];
    }
    public function testWebReadCsv(){
        $this->options['mode'] = 'web';
        $this->file_path = Yii::getAlias('@data_parser') . '\csv_parser\web.csv';
        $this->data = Yii::$app->multiparser->parse( $this->file_path, $this->options );
        $this->assertNotEmpty( $this->data, 'Output array is empty' );
    }
    public function testConsoleReadCsv(){
        $this->options[ 'mode' ] = 'console';
        $this->options[ 'keys' ] = [ 'DESCR','ARTICLE','BRAND', 'BOX', 'PRICE' ];
        $this->file_path = Yii::getAlias('@data_parser') . '\csv_parser\console.csv';
        $this->data = Yii::$app->multiparser->parse( $this->file_path, $this->options );
        $this->assertNotEmpty( $this->data, 'Output array is empty' );
        $this->assertArrayHasKey( 'ARTICLE', $this->data[0], 'Output array don`t have key - ARTICLE'  );
    }
}