|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * OpenMage |
| 5 | + * |
| 6 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 7 | + * that is bundled with this package in the file LICENSE.txt. |
| 8 | + * It is also available at https://opensource.org/license/osl-3-0-php |
| 9 | + * |
| 10 | + * @category OpenMage |
| 11 | + * @package OpenMage_Tests |
| 12 | + * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) |
| 13 | + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 14 | + */ |
| 15 | + |
| 16 | +declare(strict_types=1); |
| 17 | + |
| 18 | +namespace OpenMage\Tests\Unit\Mage\Core\Helper; |
| 19 | + |
| 20 | +use Exception; |
| 21 | +use Generator; |
| 22 | +use Mage; |
| 23 | +use Mage_Core_Helper_UnserializeArray; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | +use Varien_Object; |
| 26 | + |
| 27 | +class UnserializeArrayTest extends TestCase |
| 28 | +{ |
| 29 | + public Mage_Core_Helper_UnserializeArray $subject; |
| 30 | + |
| 31 | + public function setUp(): void |
| 32 | + { |
| 33 | + Mage::app(); |
| 34 | + $this->subject = Mage::helper('core/unserializeArray'); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @dataProvider provideUnserialize |
| 39 | + * @group Mage_Core |
| 40 | + * @group Mage_Core_Helper |
| 41 | + */ |
| 42 | + public function testUnserialize($expectedTesult, $string): void |
| 43 | + { |
| 44 | + try { |
| 45 | + $this->assertSame($expectedTesult, $this->subject->unserialize($string)); |
| 46 | + } catch (Exception $exception) { |
| 47 | + $this->assertSame($expectedTesult, $exception->getMessage()); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public function provideUnserialize(): Generator |
| 52 | + { |
| 53 | + yield 'null' => [ |
| 54 | + 'Error unserializing data.', |
| 55 | + null, |
| 56 | + ]; |
| 57 | + yield 'empty string' => [ |
| 58 | + 'Error unserializing data.', |
| 59 | + '', |
| 60 | + ]; |
| 61 | + yield 'random string' => [ |
| 62 | + 'unserialize(): Error at offset 0 of 3 bytes', |
| 63 | + 'abc', |
| 64 | + ]; |
| 65 | + yield 'valid' => [ |
| 66 | + ['key' => 'value'], |
| 67 | + 'a:1:{s:3:"key";s:5:"value";}', |
| 68 | + ]; |
| 69 | + } |
| 70 | +} |
0 commit comments