Просмотр исходного кода

followed Style CI code styke recommendations

El RIDO 9 лет назад
Родитель
Сommit
7277eef7f2
4 измененных файлов с 64 добавлено и 90 удалено
  1. 13 13
      tst/Bootstrap.php
  2. 45 67
      tst/FilterTest.php
  3. 2 3
      tst/SjclTest.php
  4. 4 7
      tst/Vizhash16x16Test.php

+ 13 - 13
tst/Bootstrap.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
-use PrivateBin\Persistence\ServerSalt;
 use Eris\Generator;
 use Eris\Generator;
+use PrivateBin\Persistence\ServerSalt;
 
 
 error_reporting(E_ALL | E_STRICT);
 error_reporting(E_ALL | E_STRICT);
 
 
@@ -137,14 +137,14 @@ class Helper
      */
      */
     public static function getPasteGenerator($meta = array(), $withAttachment = false)
     public static function getPasteGenerator($meta = array(), $withAttachment = false)
     {
     {
-        $generatedMeta = array(
+        $generatedMeta  = array(
             'salt'           => ServerSalt::generate(),
             'salt'           => ServerSalt::generate(),
             'formatter'      => Generator\elements('plaintext', 'syntaxhighlighting', 'markdown'),
             'formatter'      => Generator\elements('plaintext', 'syntaxhighlighting', 'markdown'),
             'postdate'       => Generator\int(),
             'postdate'       => Generator\int(),
             'opendiscussion' => Generator\elements(true, false),
             'opendiscussion' => Generator\elements(true, false),
         );
         );
-        $generatedMeta = array_merge($generatedMeta, $meta);
-        $example = array(
+        $generatedMeta  = array_merge($generatedMeta, $meta);
+        $example        = array(
             'data'      => Generator\associative(array(
             'data'      => Generator\associative(array(
                 'iv'    => Generator\vector(16, Generator\byte()),
                 'iv'    => Generator\vector(16, Generator\byte()),
                 'v'     => 1,
                 'v'     => 1,
@@ -172,22 +172,22 @@ class Helper
      */
      */
     public static function getPasteFromGeneratedArray($paste)
     public static function getPasteFromGeneratedArray($paste)
     {
     {
-        $paste['data']['iv'] = self::byteArray2Base64($paste['data']['iv']);
+        $paste['data']['iv']   = self::byteArray2Base64($paste['data']['iv']);
         $paste['data']['salt'] = self::byteArray2Base64($paste['data']['salt']);
         $paste['data']['salt'] = self::byteArray2Base64($paste['data']['salt']);
         // deflate cipher text to maximize entropy
         // deflate cipher text to maximize entropy
-        $paste['data']['ct'] = self::byteArray2Base64($paste['data']['ct'], true);
-        $paste['data'] = json_encode($paste['data']);
+        $paste['data']['ct']   = self::byteArray2Base64($paste['data']['ct'], true);
+        $paste['data']         = json_encode($paste['data']);
         if (array_key_exists('attachment', $paste)) {
         if (array_key_exists('attachment', $paste)) {
-            $paste['attachment']['iv'] = self::byteArray2Base64($paste['attachment']['iv']);
+            $paste['attachment']['iv']   = self::byteArray2Base64($paste['attachment']['iv']);
             $paste['attachment']['salt'] = self::byteArray2Base64($paste['attachment']['salt']);
             $paste['attachment']['salt'] = self::byteArray2Base64($paste['attachment']['salt']);
-            $paste['attachment']['ct'] = self::byteArray2Base64($paste['attachment']['ct'], true);
-            $paste['attachment'] = json_encode($paste['attachment']);
+            $paste['attachment']['ct']   = self::byteArray2Base64($paste['attachment']['ct'], true);
+            $paste['attachment']         = json_encode($paste['attachment']);
         }
         }
         if (array_key_exists('attachmentname', $paste)) {
         if (array_key_exists('attachmentname', $paste)) {
-            $paste['attachmentname']['iv'] = self::byteArray2Base64($paste['attachmentname']['iv']);
+            $paste['attachmentname']['iv']   = self::byteArray2Base64($paste['attachmentname']['iv']);
             $paste['attachmentname']['salt'] = self::byteArray2Base64($paste['attachmentname']['salt']);
             $paste['attachmentname']['salt'] = self::byteArray2Base64($paste['attachmentname']['salt']);
-            $paste['attachmentname']['ct'] = self::byteArray2Base64($paste['attachmentname']['ct'], true);
-            $paste['attachmentname'] = json_encode($paste['attachmentname']);
+            $paste['attachmentname']['ct']   = self::byteArray2Base64($paste['attachmentname']['ct'], true);
+            $paste['attachmentname']         = json_encode($paste['attachmentname']);
         }
         }
         return $paste;
         return $paste;
     }
     }

+ 45 - 67
tst/FilterTest.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
-use PrivateBin\Filter;
 use Eris\Generator;
 use Eris\Generator;
+use PrivateBin\Filter;
 
 
 class FilterTest extends PHPUnit_Framework_TestCase
 class FilterTest extends PHPUnit_Framework_TestCase
 {
 {
@@ -23,8 +23,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
                 'sec', 'second', 'seconds'
                 'sec', 'second', 'seconds'
             )
             )
         )->then(
         )->then(
-            function ($int, $unit)
-            {
+            function ($int, $unit) {
                 $suffix = $int === 1 ? '' : 's';
                 $suffix = $int === 1 ? '' : 's';
                 $this->assertEquals($int . ' second' . $suffix, Filter::formatHumanReadableTime($int . $unit));
                 $this->assertEquals($int . ' second' . $suffix, Filter::formatHumanReadableTime($int . $unit));
             }
             }
@@ -35,8 +34,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
                 'min', 'minute', 'minutes'
                 'min', 'minute', 'minutes'
             )
             )
         )->then(
         )->then(
-            function ($int, $unit)
-            {
+            function ($int, $unit) {
                 $suffix = $int === 1 ? '' : 's';
                 $suffix = $int === 1 ? '' : 's';
                 $this->assertEquals($int . ' minute' . $suffix, Filter::formatHumanReadableTime($int . $unit));
                 $this->assertEquals($int . ' minute' . $suffix, Filter::formatHumanReadableTime($int . $unit));
             }
             }
@@ -48,8 +46,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
                 'month', 'months', 'year', 'years'
                 'month', 'months', 'year', 'years'
             )
             )
         )->then(
         )->then(
-            function ($int, $unit)
-            {
+            function ($int, $unit) {
                 $suffix = $int === 1 ? '' : 's';
                 $suffix = $int === 1 ? '' : 's';
                 $this->assertEquals($int . ' ' . rtrim($unit, 's') . $suffix, Filter::formatHumanReadableTime($int . $unit));
                 $this->assertEquals($int . ' ' . rtrim($unit, 's') . $suffix, Filter::formatHumanReadableTime($int . $unit));
             }
             }
@@ -65,8 +62,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string)
-            {
+            function ($string) {
                 Filter::formatHumanReadableTime($string);
                 Filter::formatHumanReadableTime($string);
             }
             }
         );
         );
@@ -77,85 +73,79 @@ class FilterTest extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\neg()
             Generator\neg()
         )->then(
         )->then(
-            function ($int)
-            {
+            function ($int) {
                 $this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = 0;
+        $from     = 0;
         $exponent = 1024;
         $exponent = 1024;
-        $to = $exponent - 1;
+        $to       = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to)
             Generator\choose($from, $to)
         )->then(
         )->then(
-            function ($int)
-            {
+            function ($int) {
                 $this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int, 0, '.', ' ') . ' B', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to),
             Generator\choose($from, $to),
             $from
             $from
         )->then(
         )->then(
-            function ($int, $divisor)
-            {
+            function ($int, $divisor) {
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' KiB', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' KiB', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to),
             Generator\choose($from, $to),
             $from
             $from
         )->then(
         )->then(
-            function ($int, $divisor)
-            {
+            function ($int, $divisor) {
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' MiB', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' MiB', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to),
             Generator\choose($from, $to),
             $from
             $from
         )->then(
         )->then(
-            function ($int, $divisor)
-            {
+            function ($int, $divisor) {
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' GiB', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' GiB', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to),
             Generator\choose($from, $to),
             $from
             $from
         )->then(
         )->then(
-            function ($int, $divisor)
-            {
+            function ($int, $divisor) {
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' TiB', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' TiB', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
         $this->forAll(
         $this->forAll(
             Generator\choose($from, $to),
             Generator\choose($from, $to),
             $from
             $from
         )->then(
         )->then(
-            function ($int, $divisor)
-            {
+            function ($int, $divisor) {
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' PiB', Filter::formatHumanReadableSize($int));
                 $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' PiB', Filter::formatHumanReadableSize($int));
             }
             }
         );
         );
-        $from = $exponent;
+        $from      = $exponent;
         $exponent *= 1024;
         $exponent *= 1024;
-        $to = $exponent - 1;
+        $to        = $exponent - 1;
+
         // on 64bit systems, this gets larger then PHP_INT_MAX, so PHP casts it
         // on 64bit systems, this gets larger then PHP_INT_MAX, so PHP casts it
         // to double and the "choose" generator can't handle it
         // to double and the "choose" generator can't handle it
         if ($to > PHP_INT_MAX) {
         if ($to > PHP_INT_MAX) {
@@ -173,32 +163,29 @@ class FilterTest extends PHPUnit_Framework_TestCase
                 Generator\choose($from, $to),
                 Generator\choose($from, $to),
                 $from
                 $from
             )->then(
             )->then(
-                function ($int, $divisor)
-                {
+                function ($int, $divisor) {
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' EiB', Filter::formatHumanReadableSize($int));
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' EiB', Filter::formatHumanReadableSize($int));
                 }
                 }
             );
             );
-            $from = $exponent;
+            $from      = $exponent;
             $exponent *= 1024;
             $exponent *= 1024;
-            $to = $exponent - 1;
+            $to        = $exponent - 1;
             $this->forAll(
             $this->forAll(
                 Generator\choose($from, $to),
                 Generator\choose($from, $to),
                 $from
                 $from
             )->then(
             )->then(
-                function ($int, $divisor)
-                {
+                function ($int, $divisor) {
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' ZiB', Filter::formatHumanReadableSize($int));
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' ZiB', Filter::formatHumanReadableSize($int));
                 }
                 }
             );
             );
-            $from = $exponent;
+            $from      = $exponent;
             $exponent *= 1024;
             $exponent *= 1024;
-            $to = $exponent - 1;
+            $to        = $exponent - 1;
             $this->forAll(
             $this->forAll(
                 Generator\choose($from, $to),
                 Generator\choose($from, $to),
                 $from
                 $from
             )->then(
             )->then(
-                function ($int, $divisor)
-                {
+                function ($int, $divisor) {
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' YiB', Filter::formatHumanReadableSize($int));
                     $this->assertEquals(number_format($int / $divisor, 2, '.', ' ') . ' YiB', Filter::formatHumanReadableSize($int));
                 }
                 }
             );
             );
@@ -210,40 +197,35 @@ class FilterTest extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string)
-            {
+            function ($string) {
                 $this->assertTrue(Filter::slowEquals($string, $string), 'same string');
                 $this->assertTrue(Filter::slowEquals($string, $string), 'same string');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\int()
             Generator\int()
         )->then(
         )->then(
-            function ($int)
-            {
+            function ($int) {
                 $this->assertTrue(Filter::slowEquals($int, $int), 'same integer');
                 $this->assertTrue(Filter::slowEquals($int, $int), 'same integer');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\float()
             Generator\float()
         )->then(
         )->then(
-            function ($float)
-            {
+            function ($float) {
                 $this->assertTrue(Filter::slowEquals($float, $float), 'same float');
                 $this->assertTrue(Filter::slowEquals($float, $float), 'same float');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string)
-            {
+            function ($string) {
                 $this->assertFalse(Filter::slowEquals($string, true), 'string and boolean true');
                 $this->assertFalse(Filter::slowEquals($string, true), 'string and boolean true');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string)
-            {
+            function ($string) {
                 // false is casted into an empty string
                 // false is casted into an empty string
                 if ($string !== '') {
                 if ($string !== '') {
                     $this->assertFalse(Filter::slowEquals($string, false), 'string and boolean false');
                     $this->assertFalse(Filter::slowEquals($string, false), 'string and boolean false');
@@ -263,8 +245,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
             Generator\string(),
             Generator\string(),
             Generator\float()
             Generator\float()
         )->then(
         )->then(
-            function ($string, $float)
-            {
+            function ($string, $float) {
                 $this->assertFalse(Filter::slowEquals($string, $float), 'string and float');
                 $this->assertFalse(Filter::slowEquals($string, $float), 'string and float');
             }
             }
         );
         );
@@ -272,8 +253,7 @@ class FilterTest extends PHPUnit_Framework_TestCase
             Generator\string(),
             Generator\string(),
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string1, $string2)
-            {
+            function ($string1, $string2) {
                 if ($string1 !== $string2) {
                 if ($string1 !== $string2) {
                     $this->assertFalse(Filter::slowEquals($string1, $string2), 'different strings');
                     $this->assertFalse(Filter::slowEquals($string1, $string2), 'different strings');
                 }
                 }
@@ -282,27 +262,25 @@ class FilterTest extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string)
-            {
+            function ($string) {
                 $this->assertFalse(Filter::slowEquals($string, ' ' . $string), 'strings with space');
                 $this->assertFalse(Filter::slowEquals($string, ' ' . $string), 'strings with space');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\float()
             Generator\float()
         )->then(
         )->then(
-            function ($float)
-            {
+            function ($float) {
                 $this->assertFalse(Filter::slowEquals(strval($float), $float . '0'), 'floats as strings');
                 $this->assertFalse(Filter::slowEquals(strval($float), $float . '0'), 'floats as strings');
             }
             }
         );
         );
         $this->forAll(
         $this->forAll(
             Generator\int()
             Generator\int()
         )->then(
         )->then(
-            function ($int)
-            {
+            function ($int) {
                 $this->assertFalse(Filter::slowEquals($int . 'e3', $int . '000'), 'integers as strings');
                 $this->assertFalse(Filter::slowEquals($int . 'e3', $int . '000'), 'integers as strings');
             }
             }
         );
         );
+
         // these two tests would be compared equal if casted to integers as they are larger then PHP_INT_MAX
         // these two tests would be compared equal if casted to integers as they are larger then PHP_INT_MAX
         $this->assertFalse(Filter::slowEquals('9223372036854775807', '9223372036854775808'), 'large integers as strings');
         $this->assertFalse(Filter::slowEquals('9223372036854775807', '9223372036854775808'), 'large integers as strings');
         $this->assertFalse(Filter::slowEquals('61529519452809720693702583126814', '61529519452809720000000000000000'), 'larger integers as strings');
         $this->assertFalse(Filter::slowEquals('61529519452809720693702583126814', '61529519452809720000000000000000'), 'larger integers as strings');

+ 2 - 3
tst/SjclTest.php

@@ -1,7 +1,7 @@
 <?php
 <?php
 
 
-use PrivateBin\Sjcl;
 use Eris\Generator;
 use Eris\Generator;
+use PrivateBin\Sjcl;
 
 
 class SjclTest extends PHPUnit_Framework_TestCase
 class SjclTest extends PHPUnit_Framework_TestCase
 {
 {
@@ -15,8 +15,7 @@ class SjclTest extends PHPUnit_Framework_TestCase
             Generator\string(),
             Generator\string(),
             Generator\choose(0,100)
             Generator\choose(0,100)
         )->then(
         )->then(
-            function ($pasteArray, $key, $value, $lowInt)
-            {
+            function ($pasteArray, $key, $value, $lowInt) {
                 $paste = Helper::getPasteFromGeneratedArray($pasteArray);
                 $paste = Helper::getPasteFromGeneratedArray($pasteArray);
                 $this->assertTrue(Sjcl::isValid($paste['data']), 'valid sjcl');
                 $this->assertTrue(Sjcl::isValid($paste['data']), 'valid sjcl');
                 $this->assertTrue(Sjcl::isValid($paste['attachment']), 'valid sjcl');
                 $this->assertTrue(Sjcl::isValid($paste['attachment']), 'valid sjcl');

+ 4 - 7
tst/Vizhash16x16Test.php

@@ -1,8 +1,8 @@
 <?php
 <?php
 
 
+use Eris\Generator;
 use PrivateBin\Persistence\ServerSalt;
 use PrivateBin\Persistence\ServerSalt;
 use PrivateBin\Vizhash16x16;
 use PrivateBin\Vizhash16x16;
-use Eris\Generator;
 
 
 class Vizhash16x16Test extends PHPUnit_Framework_TestCase
 class Vizhash16x16Test extends PHPUnit_Framework_TestCase
 {
 {
@@ -36,8 +36,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
             Generator\string(),
             Generator\string(),
             Generator\string()
             Generator\string()
         )->then(
         )->then(
-            function ($string1, $string2)
-            {
+            function ($string1, $string2) {
                 $vz      = new Vizhash16x16();
                 $vz      = new Vizhash16x16();
                 $pngdata = $vz->generate($string1);
                 $pngdata = $vz->generate($string1);
 
 
@@ -62,8 +61,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\vector(2, Generator\vector(4, Generator\byte()))
             Generator\vector(2, Generator\vector(4, Generator\byte()))
         )->then(
         )->then(
-            function ($ips)
-            {
+            function ($ips) {
                 $hash1   = hash('sha512', implode('.', $ips[0]));
                 $hash1   = hash('sha512', implode('.', $ips[0]));
                 $hash2   = hash('sha512', implode('.', $ips[1]));
                 $hash2   = hash('sha512', implode('.', $ips[1]));
                 $vz      = new Vizhash16x16();
                 $vz      = new Vizhash16x16();
@@ -84,8 +82,7 @@ class Vizhash16x16Test extends PHPUnit_Framework_TestCase
         $this->forAll(
         $this->forAll(
             Generator\vector(2, Generator\vector(16, Generator\byte()))
             Generator\vector(2, Generator\vector(16, Generator\byte()))
         )->then(
         )->then(
-            function ($ips)
-            {
+            function ($ips) {
                 $hash1   = hash('sha512', inet_ntop(implode(array_map('chr', $ips[0]))));
                 $hash1   = hash('sha512', inet_ntop(implode(array_map('chr', $ips[0]))));
                 $hash2   = hash('sha512', inet_ntop(implode(array_map('chr', $ips[1]))));
                 $hash2   = hash('sha512', inet_ntop(implode(array_map('chr', $ips[1]))));
                 $vz      = new Vizhash16x16();
                 $vz      = new Vizhash16x16();