Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SerializeTest.php
Go to the documentation of this file.
1 <?php
7 
9 use Magento\Framework\Serialize\Signer;
10 use Magento\Framework\Serialize\InvalidSignatureException;
11 
12 class SerializeTest extends \PHPUnit\Framework\TestCase
13 {
17  private $serialize;
18 
19  protected function setUp()
20  {
21  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
22  $this->serialize = $objectManager->getObject(Serialize::class);
23  }
24 
30  public function testSerialize($value, $serializedValue)
31  {
32  $this->assertEquals($serializedValue, $this->serialize->serialize($value));
33  }
34 
38  public function serializeDataProvider()
39  {
40  return [
41  ['string', 's:6:"string";'],
42  ['', 's:0:"";'],
43  [10, 'i:10;'],
44  [10.5, 'd:10.5;'],
45  [null, 'N;'],
46  [false, 'b:0;'],
47  [['foo' => 'bar'], 'a:1:{s:3:"foo";s:3:"bar";}'],
48  ];
49  }
50 
56  public function testUnserialize($serializedValue, $value)
57  {
58  $this->assertEquals($value, $this->serialize->unserialize($serializedValue));
59  }
60 
64  public function unserializeDataProvider()
65  {
66  return [
67  ['s:6:"string";', 'string'],
68  ['s:0:"";', ''],
69  ['i:10;', 10],
70  ['d:10.5;', 10.5],
71  ['N;', null],
72  ['b:0;', false],
73  ['a:1:{s:3:"foo";s:3:"bar";}', ['foo' => 'bar']],
74  ];
75  }
76 
81  public function testSerializeException()
82  {
83  $this->serialize->serialize(STDOUT);
84  }
85 
92  {
93  $this->serialize->unserialize($value);
94  }
95 
100  {
101  return [
102  [''],
103  [false],
104  [null]
105  ];
106  }
107 
113  {
114  $this->serialize->unserialize('a:');
115  }
116 }
$objectManager
Definition: bootstrap.php:17
$value
Definition: gender.phtml:16