BaseConverterTest.php
1.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace tests\unit;
use Yii;
use yii\multiparser\Converter;
class BaseConverterTest extends \Codeception\TestCase\Test
{
    /**
     * @var \UnitTester
     */
    private $converter;
    private $configuration;
    private $wrong_configuration;
    private $data_in;
    private $data_out;
    public function _before()
    {
        $this->converter = new Converter();
        $this->configuration = ['configuration' =>
            ["encode"   => 'encode',
            "string"   => ['string1', 'string2' ],
            "float"   => 'float',
            "integer"   => ['integer1', 'integer2' ],
         ]];
        $this->wrong_configuration = ['config' =>
            ["encode"   => 'encode',
            "string"   => 'string',
            "float"   => 'float',
            "integer"   => 'integer',
         ]];
        $this->data_in = [
            "encode"   => iconv( 'UTF-8', 'windows-1251', 'test encode string' ),
            "string1"   => 43,
            "string2"   => 45.45,
            "float"   => '100.67',
            "integer1"   => '43.5',
            "integer2"   =>  45.45,
        ];
    }
    public function testConvertByConfig(){
        $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->configuration );
        $this->assertEquals( $this->data_out['encode'], iconv( 'windows-1251', 'UTF-8', 'test encode string' ), 'Encoding failed' );
        $this->assertInternalType( 'float', $this->data_out['float'], 'Convert to float is failed' );
    }
    public function testConvertToException(){
        $this->setExpectedException('\Exception');
        $this->data_out = $this->converter->convertByConfiguration($this->data_in, $this->wrong_configuration );
    }
}