Skip to content

Commit

Permalink
Tweak transformer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Feb 4, 2020
1 parent 8ad636b commit 249a47a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
14 changes: 4 additions & 10 deletions tests/Unit/TypeTransformer/BinTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@ public function testPackBinary() : void
$packed = "\xc4\x03\x61\x62\x63";

$packer = $this->createMock(Packer::class);
$packer->expects(self::any())->method('packBin')
$packer->expects(self::once())->method('packBin')
->with($raw)
->willReturn($packed);

$transformer = new BinTransformer();
$binary = new Bin($raw);

self::assertSame($packed, $transformer->pack($packer, $binary));
self::assertSame($packed, $transformer->pack($packer, new Bin($raw)));
}

public function testPackNonBinary() : void
{
$raw = 'abc';
$packed = "\xc4\x03\x61\x62\x63";

$packer = $this->createMock(Packer::class);
$packer->expects(self::any())->method('packBin')
->with($raw)
->willReturn($packed);
$packer->expects(self::never())->method('packBin');

$transformer = new BinTransformer();

self::assertNull($transformer->pack($packer, $raw));
self::assertNull($transformer->pack($packer, 'abc'));
}
}
14 changes: 4 additions & 10 deletions tests/Unit/TypeTransformer/MapTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,22 @@ public function testPackMap() : void
$packed = "\x81\xa3\x61\x62\x63\x05";

$packer = $this->createMock(Packer::class);
$packer->expects(self::any())->method('packMap')
$packer->expects(self::once())->method('packMap')
->with($raw)
->willReturn($packed);

$transformer = new MapTransformer();
$map = new Map($raw);

self::assertSame($packed, $transformer->pack($packer, $map));
self::assertSame($packed, $transformer->pack($packer, new Map($raw)));
}

public function testPackNonMap() : void
{
$raw = ['abc' => 5];
$packed = "\x81\xa3\x61\x62\x63\x05";

$packer = $this->createMock(Packer::class);
$packer->expects(self::any())->method('packMap')
->with($raw)
->willReturn($packed);
$packer->expects(self::never())->method('packMap');

$transformer = new MapTransformer();

self::assertNull($transformer->pack($packer, $raw));
self::assertNull($transformer->pack($packer, ['abc' => 5]));
}
}

0 comments on commit 249a47a

Please sign in to comment.