Blame view

tests/unit/BaseConverterTest.php 1.75 KB
207c9e2a   Mihail   add details descr...
1
2
3
4
5
  <?php
  namespace tests\unit;
  
  
  use Yii;
e8be11d4   Mihail   move multyparser ...
6
  use common\components\parsers\Converter;
207c9e2a   Mihail   add details descr...
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  
  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();
  
d11ec8b2   Mihail   fixed permissions...
24
25
26
27
28
29
          $this->configuration = ['hasKey' => true,
              'configuration' =>
              ['encode'   => 'encode',
              'string'   => ['string1', 'string2' ],
              'float'   => 'float',
              'integer'   => ['integer1', 'integer2' ],
207c9e2a   Mihail   add details descr...
30
31
32
           ]];
  
          $this->wrong_configuration = ['config' =>
d11ec8b2   Mihail   fixed permissions...
33
34
35
36
              ['encode'   => 'encode',
              'string'   => 'string',
              'float'   => 'float',
              'integer'   => 'integer',
207c9e2a   Mihail   add details descr...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
           ]];
  
          $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(){
  
d11ec8b2   Mihail   fixed permissions...
53
          $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->configuration );
207c9e2a   Mihail   add details descr...
54
55
56
57
58
59
60
61
          $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');
d11ec8b2   Mihail   fixed permissions...
62
          $this->data_out = $this->converter->convertByConfiguration( $this->data_in, $this->wrong_configuration );
207c9e2a   Mihail   add details descr...
63
64
65
66
67
68
  
      }
  
  
  
  }