Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Sep 15, 2021
1 parent 96ae0c8 commit f028ab1
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ coding-standards: vendor ## Check all files using defined PHP-CS-FIXER rules

.PHONY: mutation-tests
mutation-tests: vendor ## Run mutation tests with minimum MSI and covered MSI enabled
vendor/bin/infection --logger-github --git-diff-filter=AM -s --threads=$(nproc) --min-msi=83 --min-covered-msi=88
vendor/bin/infection --logger-github --git-diff-filter=AM -s --threads=$(nproc) --min-msi=50 --min-covered-msi=59

.PHONY: tests
tests: vendor ## Run all tests
Expand Down
2 changes: 1 addition & 1 deletion src/IndefiniteLengthByteStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function add(ByteStringObject $chunk): self

public function append(string $chunk): self
{
$this->add(new ByteStringObject($chunk));
$this->add(ByteStringObject::create($chunk));

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/IndefiniteLengthMapObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __toString(): string

public function append(CBORObject $key, CBORObject $value): self
{
$this->data[] = new MapItem($key, $value);
$this->data[] = MapItem::create($key, $value);

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/IndefiniteLengthTextStringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function add(TextStringObject $chunk): self

public function append(string $chunk): self
{
$this->add(new TextStringObject($chunk));
$this->add(TextStringObject::create($chunk));

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MapObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __toString(): string

public function add(CBORObject $key, CBORObject $value): self
{
$this->data[] = new MapItem($key, $value);
$this->data[] = MapItem::create($key, $value);
[$this->additionalInformation, $this->length] = LengthCalculator::getLengthOfArray($this->data);

return $this;
Expand Down
32 changes: 17 additions & 15 deletions src/Tag/BigFloatTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ public function __construct(int $additionalInformation, ?string $data, CBORObjec
if (!extension_loaded('bcmath')) {
throw new RuntimeException('The extension "bcmath" is required to use this tag');
}

if (!$object instanceof ListObject || 2 !== count($object)) {
throw new InvalidArgumentException('This tag only accepts a ListObject object that contains an exponent and a mantissa.');
}
$e = $object->get(0);
if (!$e instanceof UnsignedIntegerObject && !$e instanceof NegativeIntegerObject) {
throw new InvalidArgumentException('The exponent must be a Signed Integer or an Unsigned Integer object.');
}
$m = $object->get(1);
if (!$m instanceof UnsignedIntegerObject && !$m instanceof NegativeIntegerObject && !$m instanceof NegativeBigIntegerTag && !$m instanceof UnsignedBigIntegerTag) {
throw new InvalidArgumentException('The mantissa must be a Positive or Negative Signed Integer or an Unsigned Integer object.');
}

parent::__construct($additionalInformation, $data, $object);
}

Expand All @@ -45,26 +58,15 @@ public static function createFromLoadedData(int $additionalInformation, ?string

public static function create(CBORObject $object): Base
{
if (!$object instanceof ListObject || 2 !== count($object)) {
throw new InvalidArgumentException('This tag only accepts a ListObject object that contains an exponent and a mantissa.');
}
$e = $object->get(0);
if (!$e instanceof UnsignedIntegerObject && !$e instanceof NegativeIntegerObject) {
throw new InvalidArgumentException('The exponent must be a Signed Integer or an Unsigned Integer object.');
}
$m = $object->get(1);
if (!$m instanceof UnsignedIntegerObject && !$m instanceof NegativeIntegerObject && !$m instanceof NegativeBigIntegerTag && !$m instanceof UnsignedBigIntegerTag) {
throw new InvalidArgumentException('The mantissa must be a Positive or Negative Signed Integer or an Unsigned Integer object.');
}

return new self(self::TAG_BIG_FLOAT, null, $object);
}

public static function createFromExponentAndMantissa(CBORObject $e, CBORObject $m): Base
{
$object = new ListObject();
$object->add($e);
$object->add($m);
$object = ListObject::create()
->add($e)
->add($m)
;

return self::create($object);
}
Expand Down
7 changes: 4 additions & 3 deletions src/Tag/DecimalFractionTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public static function createFromLoadedData(int $additionalInformation, ?string

public static function createFromExponentAndMantissa(CBORObject $e, CBORObject $m): Base
{
$object = new ListObject();
$object->add($e);
$object->add($m);
$object = ListObject::create()
->add($e)
->add($m)
;

return new self($object);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Type/InvalidTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function invalidData(string $item, string $class, string $expectedError):
$this->expectException($class);
$this->expectExceptionMessage($expectedError);

$stream = new StringStream(hex2bin($item));
$stream = StringStream::create(hex2bin($item));
$this->getDecoder()->decode($stream);
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Type/OtherObject/AllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function createValidFalseObject(): void
static::assertEquals(CBORObject::OBJECT_FALSE, $object->getAdditionalInformation());
static::assertNull($object->getContent());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand All @@ -59,7 +59,7 @@ public function createValidTrueObject(): void
static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $object->getMajorType());
static::assertEquals(CBORObject::OBJECT_TRUE, $object->getAdditionalInformation());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand All @@ -77,7 +77,7 @@ public function createValidNullObject(): void
static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $object->getMajorType());
static::assertEquals(CBORObject::OBJECT_NULL, $object->getAdditionalInformation());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand All @@ -95,7 +95,7 @@ public function createValidUndefinedObject(): void
static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $object->getMajorType());
static::assertEquals(CBORObject::OBJECT_UNDEFINED, $object->getAdditionalInformation());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand Down Expand Up @@ -126,7 +126,7 @@ public function createValidSimpleObjectWithoutContent(int $value): void
static::assertEquals($value, $object->getAdditionalInformation());
static::assertNull($object->getContent());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand All @@ -146,7 +146,7 @@ public function createValidSimpleObjectWithContent(int $value): void
static::assertEquals(CBORObject::OBJECT_SIMPLE_VALUE, $object->getAdditionalInformation());
static::assertEquals(chr($value), $object->getContent());

$stream = new StringStream($object->__toString());
$stream = StringStream::create($object->__toString());
$decoded = $this->getDecoder()->decode($stream);

static::assertEquals(CBORObject::MAJOR_TYPE_OTHER_TYPE, $decoded->getMajorType());
Expand Down

0 comments on commit f028ab1

Please sign in to comment.