File: InflectorTest.php

package info (click to toggle)
php-doctrine-inflector 2.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 536 kB
  • sloc: php: 3,308; makefile: 17
file content (146 lines) | stat: -rw-r--r-- 4,213 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Inflector;

use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\WordInflector;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class InflectorTest extends TestCase
{
    /** @var WordInflector&MockObject */
    private $singularInflector;

    /** @var WordInflector&MockObject */
    private $pluralInflector;

    /** @var Inflector */
    private $inflector;

    public function testTableize(): void
    {
        self::assertSame('model_name', $this->inflector->tableize('ModelName'));
        self::assertSame('model_name', $this->inflector->tableize('modelName'));
        self::assertSame('model_name', $this->inflector->tableize('model_name'));
    }

    public function testClassify(): void
    {
        self::assertSame('ModelName', $this->inflector->classify('model_name'));
        self::assertSame('ModelName', $this->inflector->classify('modelName'));
        self::assertSame('ModelName', $this->inflector->classify('ModelName'));
    }

    public function testCamelize(): void
    {
        self::assertSame('modelName', $this->inflector->camelize('ModelName'));
        self::assertSame('modelName', $this->inflector->camelize('model_name'));
        self::assertSame('modelName', $this->inflector->camelize('modelName'));
    }

    public function testCapitalize(): void
    {
        self::assertSame(
            'Top-O-The-Morning To All_of_you!',
            $this->inflector->capitalize('top-o-the-morning to all_of_you!')
        );
    }

    public function testSeemsUtf8(): void
    {
        self::assertTrue($this->inflector->seemsUtf8('teléfono'));
        self::assertTrue($this->inflector->seemsUtf8('král'));
        self::assertTrue($this->inflector->seemsUtf8('telephone'));
    }

    public function testUnaccent(): void
    {
        self::assertSame('telefono', $this->inflector->unaccent('teléfono'));
        self::assertSame('telephone', $this->inflector->unaccent('telephone'));
    }

    /** @dataProvider dataStringsUrlize */
    #[DataProvider('dataStringsUrlize')]
    public function testUrlize(string $expected, string $string): void
    {
        self::assertSame(
            $expected,
            $this->inflector->urlize($string)
        );
    }

    /**
     * Strings which are used for testUrlize.
     *
     * @return string[][]
     */
    public static function dataStringsUrlize(): array
    {
        return [
            [
                'testing-creating-a-slug-from-a-random-string',
                'Testing_Creating a -Slug from a random-string!@#',
            ],
            [
                'contesta-el-telefono',
                'Contesta el teléfono',
            ],
            [
                'den-hund-fuettern',
                'den hund füttern',
            ],
            [
                'jsem-kral-na-severu',
                'Jsem král na severu',
            ],
            [
                'test1-test2',
                'test1::test2',
            ],
            [
                'test1-test2',
                'test1$test2',
            ],
            [
                'testab-test2',
                'TESTAb-test2',
            ],
            [
                'ano',
                'año',
            ],
        ];
    }

    public function testPluralize(): void
    {
        $this->pluralInflector->expects(self::once())
            ->method('inflect')
            ->with('in')
            ->willReturn('out');

        self::assertSame('out', $this->inflector->pluralize('in'));
    }

    public function testSingularize(): void
    {
        $this->singularInflector->expects(self::once())
            ->method('inflect')
            ->with('in')
            ->willReturn('out');

        self::assertSame('out', $this->inflector->singularize('in'));
    }

    protected function setUp(): void
    {
        $this->singularInflector = $this->createMock(WordInflector::class);
        $this->pluralInflector   = $this->createMock(WordInflector::class);

        $this->inflector = new Inflector($this->singularInflector, $this->pluralInflector);
    }
}