فهرست منبع

complete unit tests

Olivier Massot 1 سال پیش
والد
کامیت
4550595208
1فایلهای تغییر یافته به همراه53 افزوده شده و 0 حذف شده
  1. 53 0
      tests/Unit/Service/Utils/ObjectUtilsTest.php

+ 53 - 0
tests/Unit/Service/Utils/ObjectUtilsTest.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace App\Tests\Unit\Service\Utils;
+
+use App\Service\Utils\ObjectUtils;
+use PHPUnit\Framework\TestCase;
+
+class ObjectUtilsTest extends TestCase
+{
+    public function testHashWithEmptyArray()
+    {
+        $this->assertEquals(
+            '44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a',
+            ObjectUtils::hash([])
+        );
+        $this->assertEquals(
+            'bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f',
+            ObjectUtils::hash([], 'sha1')
+        );
+    }
+
+    public function testHashWithArray()
+    {
+        $this->assertEquals(
+            'e6a3385fb77c287a712e7f406a451727f0625041823ecf23bea7ef39b2e39805',
+            ObjectUtils::hash(['a' => 1, 'b' => 2, 'c' => 3])
+        );
+        $this->assertEquals(
+            'e7ec4a8f2309bdd4c4c57cb2adfb79c91a293597',
+            ObjectUtils::hash(['a' => 1, 'b' => 2, 'c' => 3], 'sha1')
+        );
+    }
+
+    public function testHashWithUnsortedArray()
+    {
+        $this->assertEquals(
+            ObjectUtils::hash(['a' => 1, 'b' => 2, 'c' => 3]),
+            ObjectUtils::hash(['b' => 2, 'a' => 1, 'c' => 3])
+        );
+        $this->assertEquals(
+            ObjectUtils::hash(['a' => 1, 'b' => 2, 'c' => 3], 'sha1'),
+            ObjectUtils::hash(['b' => 2, 'a' => 1, 'c' => 3], 'sha1')
+        );
+    }
+
+    public function testHashWithObject()
+    {
+        $this->assertEquals(
+            'e6a3385fb77c287a712e7f406a451727f0625041823ecf23bea7ef39b2e39805',
+            ObjectUtils::hash((object)['a' => 1, 'b' => 2, 'c' => 3])
+        );
+    }
+}