File: EanTest.php

package info (click to toggle)
php-faker 1.20.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,704 kB
  • sloc: php: 115,692; xml: 213; makefile: 49
file content (75 lines) | stat: -rw-r--r-- 1,834 bytes parent folder | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php

namespace Faker\Test\Calculator;

use Faker\Calculator\Ean;
use Faker\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

final class EanTest extends TestCase
{
    public static function Ean8checksumProvider()
    {
        return [
            ['1234567', 0],
            ['2345678', 5],
            ['3456789', 0],
        ];
    }

    public static function ean8ValidationProvider()
    {
        return [
            ['1234567891231', true],
            ['2354698521469', true],
            ['3001092650834', false],
            ['3921092190838', false],
            ['39210921908381', false],
        ];
    }

    #[DataProvider('Ean8checksumProvider')]
    public function testChecksumEan8($partial, $checksum)
    {
        self::assertSame($checksum, Ean::checksum($partial));
    }

    #[DataProvider('ean8ValidationProvider')]
    public function testEan8Validation($ean8, $valid)
    {
        self::assertSame($valid, Ean::isValid($ean8));
    }

    public static function Ean13checksumProvider()
    {
        return [
            ['123456789123', 1],
            ['978020137962', 4],
            ['235469852146', 9],
            ['300109265083', 5],
            ['392109219083', 7],
        ];
    }

    public static function ean13ValidationProvider()
    {
        return [
            ['1234567891231', true],
            ['2354698521469', true],
            ['3001092650834', false],
            ['3921092190838', false],
        ];
    }

    #[DataProvider('Ean13checksumProvider')]
    public function testChecksumEan13($partial, $checksum)
    {
        self::assertSame($checksum, Ean::checksum($partial));
    }

    #[DataProvider('ean13ValidationProvider')]
    public function testEan13Validation($ean13, $valid)
    {
        self::assertSame($valid, Ean::isValid($ean13));
    }
}