ArrayFixtureTest.php 1.59 KB
Newer Older
Ragazzo committed
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
<?php

/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yiiunit\framework\test;

use yiiunit\TestCase;
use yii\test\ArrayFixture;

class ArrayFixtureTest extends TestCase
{

    /**
     * @var \yii\test\ArrayFixture 
     */
    private $_fixture;

    protected function setUp()
    {
        parent::setUp();
        $this->_fixture = new ArrayFixture();
    }

    public function testLoadUnloadParticularFile()
    {
        $this->_fixture->dataFile = '@yiiunit/framework/test/data/array_fixture.php';
        $this->assertEmpty($this->_fixture->data, 'fixture data should be empty');

        $this->_fixture->load();

        $this->assertCount(2, $this->_fixture->data, 'fixture data should match needed total count');
        $this->assertEquals('customer1', $this->_fixture['customer1']['name'], 'first fixture data should match');
        $this->assertEquals('customer2@example.com', $this->_fixture['customer2']['email'], 'second fixture data should match');
    }

    public function testNothingToLoad()
    {
        $this->_fixture->dataFile = false;
        $this->assertEmpty($this->_fixture->data, 'fixture data should be empty');

        $this->_fixture->load();
        $this->assertEmpty($this->_fixture->data, 'fixture data should not be loaded');
    }

    /**
Qiang Xue committed
50
     * @expectedException \yii\base\InvalidConfigException
Ragazzo committed
51 52 53
     */
    public function testWrongDataFileException()
    {
Qiang Xue committed
54
        $this->_fixture->dataFile = 'wrong/fixtures/data/path/alias';
Ragazzo committed
55 56 57 58
        $this->_fixture->load();
    }

}