File: IsbnTest.php

package info (click to toggle)
php-faker 1.20.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,412 kB
  • sloc: php: 115,671; xml: 213; makefile: 49
file content (57 lines) | stat: -rw-r--r-- 1,207 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace Faker\Test\Calculator;

use Faker\Calculator\Isbn;
use Faker\Test\TestCase;

final class IsbnTest extends TestCase
{
    public function isbnChecksumProvider(): iterable
    {
        yield ['997150210', '0'];

        yield ['999215810', '7'];

        yield ['960425059', '0'];
    }

    public function isbnValidationProvider(): iterable
    {
        yield ['9971502100', true];

        yield ['0754013235', true];

        yield ['093583933X', true];

        yield ['0935839330', false];

        yield ['1434856045', false];

        yield ['143485604', false];

        yield ['093583933A', false];
    }

    /**
     * @dataProvider isbnChecksumProvider
     */
    public function testChecksumIsbn(string $partial, string $checksum): void
    {
        self::assertSame($checksum, Isbn::checksum($partial));
    }

    public function testInvalidChecksumIsbn(): void
    {
        $this->expectException(\LengthException::class);
        Isbn::checksum('9971502100');
    }

    /**
     * @dataProvider isbnValidationProvider
     */
    public function testIsbnValidation(string $isbn, bool $valid): void
    {
        self::assertSame($valid, Isbn::isValid($isbn));
    }
}