Example #1
0
 public function testConstructFromArray()
 {
     try {
         $pair = KeyValuePair::initFromArray([]);
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue(true);
     }
     $pair = KeyValuePair::initFromArray(['name' => 'tag']);
     $this->assertEquals('tag', '' . $pair);
     $pair = KeyValuePair::initFromArray(['name' => 'tag', 'value' => 'qwe', 'delimiter' => '=', 'canBeShort' => false, 'nameComas' => '-', 'valueComas' => '"']);
     $this->assertEquals('-tag-="qwe"', '' . $pair);
     $pair = KeyValuePair::initFromArray(['name' => 'tag', 'value' => '', 'delimiter' => '=', 'canBeShort' => true, 'nameComas' => '-', 'valueComas' => '"']);
     $this->assertEquals('-tag-', '' . $pair);
     $pair = KeyValuePair::initFromArray(['name' => 'tag', 'value' => '123', 'delimiter' => '=', 'canBeShort' => true, 'nameComas' => ['-'], 'valueComas' => ['*', '^']]);
     $this->assertEquals('-tag-=*123^', '' . $pair);
     try {
         $pair = KeyValuePair::initFromArray(['name' => 'tag', 'value' => '123', 'delimiter' => '=', 'canBeShort' => true, 'nameComas' => [['1']], 'valueComas' => ['*', 1]]);
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue(true);
     }
 }