Skip to content

Commit

Permalink
New tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Sep 29, 2021
1 parent 6376f58 commit 1588030
Show file tree
Hide file tree
Showing 22 changed files with 697 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
run: git fetch --depth=1 origin $GITHUB_BASE_REF

- name: Infection
run: make mutation-tests
run: make mutation-tests-github
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ static-analyse: vendor ## Run static analyse
rector: vendor ## Check all files using Rector
vendor/bin/rector process --ansi --dry-run

.PHONY: mutation-tests
mutation-tests: vendor ## Mutation tests
vendor/bin/infection -s --threads=$(nproc) --min-msi=60 --min-covered-msi=70

.PHONY: mutation-tests-github
mutation-tests-github: vendor ## Mutation tests (for Github only)
vendor/bin/infection --logger-github --git-diff-filter=AM -s --threads=$(nproc) --min-msi=17 --min-covered-msi=31


.DEFAULT_GOAL := help
help:
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
cacheResult="true"
bootstrap="vendor/autoload.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
Expand Down
2 changes: 1 addition & 1 deletion tests/Type/BaseTestCase.php → tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\Decoder;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\ByteStringObject;
use CBOR\CBORObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\OtherObject\DoublePrecisionFloatObject;

Expand Down
2 changes: 1 addition & 1 deletion tests/Type/FloatTest.php → tests/FloatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\StringStream;

Expand Down
2 changes: 1 addition & 1 deletion tests/Type/GlobalTest.php → tests/GlobalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\StringStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\CBORObject;
use CBOR\IndefiniteLengthByteStringObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\CBORObject;
use CBOR\IndefiniteLengthTextStringObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use Brick\Math\Exception\IntegerOverflowException;
use CBOR\StringStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type\OtherObject;
namespace CBOR\Test\OtherObject;

use CBOR\CBORObject;
use CBOR\Normalizable;
Expand All @@ -25,7 +25,7 @@
use CBOR\OtherObject\TrueObject;
use CBOR\OtherObject\UndefinedObject;
use CBOR\StringStream;
use CBOR\Test\Type\BaseTestCase;
use CBOR\Test\BaseTestCase;
use function chr;
use InvalidArgumentException;

Expand Down
2 changes: 1 addition & 1 deletion tests/Type/OtherTest.php → tests/OtherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\StringStream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\NegativeIntegerObject;
use CBOR\StringStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type\Tag;
namespace CBOR\Test\Tag;

use CBOR\ByteStringObject;
use CBOR\CBORObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type\Tag;
namespace CBOR\Test\Tag;

use CBOR\ByteStringObject;
use CBOR\CBORObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type\Tag;
namespace CBOR\Test\Tag;

use CBOR\IndefiniteLengthTextStringObject;
use CBOR\OtherObject\BreakObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type\Tag;
namespace CBOR\Test\Tag;

use CBOR\ByteStringObject;
use CBOR\CBORObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\CBORObject;
use CBOR\StringStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test\Type;
namespace CBOR\Test;

use CBOR\StringStream;
use CBOR\UnsignedIntegerObject;
Expand Down
39 changes: 39 additions & 0 deletions tests/VectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/*
* The MIT License (MIT)
*
* Copyright (c) 2018-2020 Spomky-Labs
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/

namespace CBOR\Test;

use CBOR\StringStream;

/**
* @internal
*/
final class VectorTest extends BaseTestCase
{
/**
* @test
* @dataProvider getVectors
*/
public function createOnValidValue(string $cbor, string $hex): void
{
$stream = StringStream::create(base64_decode($cbor, true));
$result = $this->getDecoder()->decode($stream);

static::assertEquals(hex2bin($hex), (string) $result);
}

public function getVectors(): array
{
return json_decode(file_get_contents(__DIR__.'/vectors.json'), true, 512, JSON_THROW_ON_ERROR);
}
}
Loading

0 comments on commit 1588030

Please sign in to comment.