File tree Expand file tree Collapse file tree 5 files changed +60
-1
lines changed
Expand file tree Collapse file tree 5 files changed +60
-1
lines changed Original file line number Diff line number Diff line change 2727 run : composer install --prefer-dist --no-interaction
2828 - name : Run PHPStan
2929 run : ./vendor/bin/phpstan analyze --no-progress
30+ - name : Run PHPUnit
31+ run : ./vendor/bin/phpunit tests/phpunit --fail-on-warning
Original file line number Diff line number Diff line change 1010 "require-dev" : {
1111 "phpstan/phpstan" : " 1.2.0" ,
1212 "phpstan/extension-installer" : " ^1.0" ,
13- "phpstan/phpstan-strict-rules" : " ^1.0.0"
13+ "phpstan/phpstan-strict-rules" : " ^1.0.0" ,
14+ "phpunit/phpunit" : " ^9.5" ,
15+ "phpstan/phpstan-phpunit" : " ^1.0"
1416 },
1517 "autoload" : {
1618 "psr-4" : {
1719 "pocketmine\\ utils\\ " : " src/"
1820 }
21+ },
22+ "autoload-dev" : {
23+ "psr-4" : {
24+ "pocketmine\\ utils\\ " : " tests/phpunit/"
25+ }
1926 }
2027}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ parameters:
22 level: 8
33 paths:
44 - src
5+ - tests/phpunit
56 ignoreErrors:
67 -
78 #this would only happen if the regex was broken
Original file line number Diff line number Diff line change @@ -103,15 +103,25 @@ public static function writeBool(bool $b) : string{
103103
104104 /**
105105 * Reads an unsigned byte (0 - 255)
106+ *
107+ * @throws BinaryDataException
106108 */
107109 public static function readByte (string $ c ) : int {
110+ if ($ c === "" ){
111+ throw new BinaryDataException ("Expected a string of length 1 " );
112+ }
108113 return ord ($ c [0 ]);
109114 }
110115
111116 /**
112117 * Reads a signed byte (-128 - 127)
118+ *
119+ * @throws BinaryDataException
113120 */
114121 public static function readSignedByte (string $ c ) : int {
122+ if ($ c === "" ){
123+ throw new BinaryDataException ("Expected a string of length 1 " );
124+ }
115125 return self ::signByte (ord ($ c [0 ]));
116126 }
117127
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ *
5+ * ____ _ _ __ __ _ __ __ ____
6+ * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7+ * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8+ * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9+ * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10+ *
11+ * This program is free software: you can redistribute it and/or modify
12+ * it under the terms of the GNU Lesser General Public License as published by
13+ * the Free Software Foundation, either version 3 of the License, or
14+ * (at your option) any later version.
15+ *
16+ * @author PocketMine Team
17+ * @link http://www.pocketmine.net/
18+ *
19+ *
20+ */
21+
22+ declare (strict_types=1 );
23+
24+ namespace pocketmine \utils ;
25+
26+ use PHPUnit \Framework \TestCase ;
27+
28+ final class BinaryTest extends TestCase{
29+
30+ public function testReadByteWithEmptyString () : void {
31+ $ this ->expectException (BinaryDataException::class);
32+ Binary::readByte ("" );
33+ }
34+
35+ public function testReadSignedByteWithEmptyString () : void {
36+ $ this ->expectException (BinaryDataException::class);
37+ Binary::readSignedByte ("" );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments