CsvParsingTest.php 1.17 KB
<?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'  );
    }



}