Skip to content

add decodertest #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/unit/DecodersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ public function testMap(): void
/** @psalm-suppress UndefinedFunction */
$this
->forAll(
Generators::int()
Generators::int() //provare il decoder con molti interi casuali
)
->then(function (int $i) use ($decoder): void {
$a = self::assertSuccessInstanceOf(
DecodersTest\A::class,
$decoder->decode($i)
);
self::assertSame($i, $a->getValue());
self::assertSame($i, $a->getValue());//verifica che il valore dentro l'oggetto A sia uguale a $i
});
}
}

namespace Tests\Facile\PhpCodec\DecodersTest;

//wrapper class usata per testare la trasformazione: prende un int e lo incapsula in un oggetto
class A
{
private int $v;
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/StringDecoderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Tests\Unit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file path should be coherent with the path of StringDecoder


use PHPUnit\Framework\TestCase;
use Facile\PhpCodec\Internal\Primitives\StringDecoder;
use Facile\PhpCodec\Validation\Context;
use Facile\PhpCodec\Validation\ValidationSuccess;

final class StringDecoderTest extends TestCase
{
public function testValidString(): void
{
$decoder = new StringDecoder();
$context = new Context($decoder); //cosa controllare

//il valore da validare passa il controllo?
$result = $decoder->validate('ciao', $context);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use directly decode instead of validate

//è ciò che mi aspettavo? (Successo)
$this->assertInstanceOf(ValidationSuccess::class, $result);
}

public function testInvalidValues(): void
{
$decoder = new StringDecoder();
$context = new Context($decoder);

foreach ([123, 3.14, true] as $input) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but try to use PHPUnit's data providers

$result = $decoder->validate($input, $context);
$this->assertNotInstanceOf(ValidationSuccess::class, $result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert on ValidationFailure instance instead

}
}
}
Loading