Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TranslatorTest.php

class TranslatorTest

Test should cover all languages mentioned on http://translate.sourceforge.net/wiki/l10n/pluralforms and Plural forms mentioned on http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms.

See also https://developer.mozilla.org/en/Localization_and_Plurals which mentions 15 rules having a maximum of 6 forms. The mozilla code is also interesting to check for.

As mentioned by chx http://drupal.org/node/1273968 we can cover all by testing number from 0 to 199

The goal to cover all languages is to far fetched so this test case is smaller.

@author Clemens Tolboom clemens@build2be.nl

Hierarchy

  • class \PHPUnit\Framework\Assert
    • class \PHPUnit\Framework\TestCase extends \PHPUnit\Framework\Assert implements \PHPUnit\Framework\Reorderable, \PHPUnit\Framework\SelfDescribing, \PHPUnit\Framework\Test
      • class \Symfony\Contracts\Translation\Test\TranslatorTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of TranslatorTest

File

vendor/symfony/translation-contracts/Test/TranslatorTest.php, line 31

Namespace

Symfony\Contracts\Translation\Test
View source
class TranslatorTest extends TestCase {
    private string $defaultLocale;
    protected function setUp() : void {
        $this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('en');
    }
    protected function tearDown() : void {
        \Locale::setDefault($this->defaultLocale);
    }
    public function getTranslator() : TranslatorInterface {
        return new class  implements TranslatorInterface {
            use TranslatorTrait;

};
    }
    
    /**
     * @dataProvider getTransTests
     */
    public function testTrans($expected, $id, $parameters) {
        $translator = $this->getTranslator();
        $this->assertEquals($expected, $translator->trans($id, $parameters));
    }
    
    /**
     * @dataProvider getTransChoiceTests
     */
    public function testTransChoiceWithExplicitLocale($expected, $id, $number) {
        $translator = $this->getTranslator();
        $this->assertEquals($expected, $translator->trans($id, [
            '%count%' => $number,
        ]));
    }
    
    /**
     * @requires extension intl
     *
     * @dataProvider getTransChoiceTests
     */
    public function testTransChoiceWithDefaultLocale($expected, $id, $number) {
        $translator = $this->getTranslator();
        $this->assertEquals($expected, $translator->trans($id, [
            '%count%' => $number,
        ]));
    }
    
    /**
     * @dataProvider getTransChoiceTests
     */
    public function testTransChoiceWithEnUsPosix($expected, $id, $number) {
        $translator = $this->getTranslator();
        $translator->setLocale('en_US_POSIX');
        $this->assertEquals($expected, $translator->trans($id, [
            '%count%' => $number,
        ]));
    }
    public function testGetSetLocale() {
        $translator = $this->getTranslator();
        $this->assertEquals('en', $translator->getLocale());
    }
    
    /**
     * @requires extension intl
     */
    public function testGetLocaleReturnsDefaultLocaleIfNotSet() {
        $translator = $this->getTranslator();
        \Locale::setDefault('pt_BR');
        $this->assertEquals('pt_BR', $translator->getLocale());
        \Locale::setDefault('en');
        $this->assertEquals('en', $translator->getLocale());
    }
    public static function getTransTests() {
        return [
            [
                'Symfony is great!',
                'Symfony is great!',
                [],
            ],
            [
                'Symfony is awesome!',
                'Symfony is %what%!',
                [
                    '%what%' => 'awesome',
                ],
            ],
        ];
    }
    public static function getTransChoiceTests() {
        return [
            [
                'There are no apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                10,
            ],
            [
                'There are 0 apples',
                'There is 1 apple|There are %count% apples',
                0,
            ],
            [
                'There is 1 apple',
                'There is 1 apple|There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                'There is 1 apple|There are %count% apples',
                10,
            ],
            // custom validation messages may be coded with a fixed value
[
                'There are 2 apples',
                'There are 2 apples',
                2,
            ],
        ];
    }
    
    /**
     * @dataProvider getInterval
     */
    public function testInterval($expected, $number, $interval) {
        $translator = $this->getTranslator();
        $this->assertEquals($expected, $translator->trans($interval . ' foo|[1,Inf[ bar', [
            '%count%' => $number,
        ]));
    }
    public static function getInterval() {
        return [
            [
                'foo',
                3,
                '{1,2, 3 ,4}',
            ],
            [
                'bar',
                10,
                '{1,2, 3 ,4}',
            ],
            [
                'bar',
                3,
                '[1,2]',
            ],
            [
                'foo',
                1,
                '[1,2]',
            ],
            [
                'foo',
                2,
                '[1,2]',
            ],
            [
                'bar',
                1,
                ']1,2[',
            ],
            [
                'bar',
                2,
                ']1,2[',
            ],
            [
                'foo',
                log(0),
                '[-Inf,2[',
            ],
            [
                'foo',
                -log(0),
                '[-2,+Inf]',
            ],
        ];
    }
    
    /**
     * @dataProvider getChooseTests
     */
    public function testChoose($expected, $id, $number, $locale = null) {
        $translator = $this->getTranslator();
        $this->assertEquals($expected, $translator->trans($id, [
            '%count%' => $number,
        ], null, $locale));
    }
    public function testReturnMessageIfExactlyOneStandardRuleIsGiven() {
        $translator = $this->getTranslator();
        $this->assertEquals('There are two apples', $translator->trans('There are two apples', [
            '%count%' => 2,
        ]));
    }
    
    /**
     * @dataProvider getNonMatchingMessages
     */
    public function testThrowExceptionIfMatchingMessageCannotBeFound($id, $number) {
        $translator = $this->getTranslator();
        $this->expectException(\InvalidArgumentException::class);
        $translator->trans($id, [
            '%count%' => $number,
        ]);
    }
    public static function getNonMatchingMessages() {
        return [
            [
                '{0} There are no apples|{1} There is one apple',
                2,
            ],
            [
                '{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                '{1} There is one apple|]2,Inf] There are %count% apples',
                2,
            ],
            [
                '{0} There are no apples|There is one apple',
                2,
            ],
        ];
    }
    public static function getChooseTests() {
        return [
            [
                'There are no apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                'There are no apples',
                '{0}     There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                'There are no apples',
                '{0}There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf] There are %count% apples',
                10,
            ],
            [
                'There are 10 apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf]There are %count% apples',
                10,
            ],
            [
                'There are 10 apples',
                '{0} There are no apples|{1} There is one apple|]1,Inf]     There are %count% apples',
                10,
            ],
            [
                'There are 0 apples',
                'There is one apple|There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                'There is one apple|There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                'There is one apple|There are %count% apples',
                10,
            ],
            [
                'There are 0 apples',
                'one: There is one apple|more: There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                'one: There is one apple|more: There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                'one: There is one apple|more: There are %count% apples',
                10,
            ],
            [
                'There are no apples',
                '{0} There are no apples|one: There is one apple|more: There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                '{0} There are no apples|one: There is one apple|more: There are %count% apples',
                1,
            ],
            [
                'There are 10 apples',
                '{0} There are no apples|one: There is one apple|more: There are %count% apples',
                10,
            ],
            [
                '',
                '{0}|{1} There is one apple|]1,Inf] There are %count% apples',
                0,
            ],
            [
                '',
                '{0} There are no apples|{1}|]1,Inf] There are %count% apples',
                1,
            ],
            // Indexed only tests which are Gettext PoFile* compatible strings.
[
                'There are 0 apples',
                'There is one apple|There are %count% apples',
                0,
            ],
            [
                'There is one apple',
                'There is one apple|There are %count% apples',
                1,
            ],
            [
                'There are 2 apples',
                'There is one apple|There are %count% apples',
                2,
            ],
            // Tests for float numbers
[
                'There is almost one apple',
                '{0} There are no apples|]0,1[ There is almost one apple|{1} There is one apple|[1,Inf] There is more than one apple',
                0.7,
            ],
            [
                'There is one apple',
                '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple',
                1,
            ],
            [
                'There is more than one apple',
                '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple',
                1.7,
            ],
            [
                'There are no apples',
                '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple',
                0,
            ],
            [
                'There are no apples',
                '{0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple',
                0.0,
            ],
            [
                'There are no apples',
                '{0.0} There are no apples|]0,1[There are %count% apples|{1} There is one apple|[1,Inf] There is more than one apple',
                0,
            ],
            // Test texts with new-lines
            // with double-quotes and \n in id & double-quotes and actual newlines in text
[
                "This is a text with a\n            new-line in it. Selector = 0.",
                '{0}This is a text with a
            new-line in it. Selector = 0.|{1}This is a text with a
            new-line in it. Selector = 1.|[1,Inf]This is a text with a
            new-line in it. Selector > 1.',
                0,
            ],
            // with double-quotes and \n in id and single-quotes and actual newlines in text
[
                "This is a text with a\n            new-line in it. Selector = 1.",
                '{0}This is a text with a
            new-line in it. Selector = 0.|{1}This is a text with a
            new-line in it. Selector = 1.|[1,Inf]This is a text with a
            new-line in it. Selector > 1.',
                1,
            ],
            [
                "This is a text with a\n            new-line in it. Selector > 1.",
                '{0}This is a text with a
            new-line in it. Selector = 0.|{1}This is a text with a
            new-line in it. Selector = 1.|[1,Inf]This is a text with a
            new-line in it. Selector > 1.',
                5,
            ],
            // with double-quotes and id split across lines
[
                'This is a text with a
            new-line in it. Selector = 1.',
                '{0}This is a text with a
            new-line in it. Selector = 0.|{1}This is a text with a
            new-line in it. Selector = 1.|[1,Inf]This is a text with a
            new-line in it. Selector > 1.',
                1,
            ],
            // with single-quotes and id split across lines
[
                'This is a text with a
            new-line in it. Selector > 1.',
                '{0}This is a text with a
            new-line in it. Selector = 0.|{1}This is a text with a
            new-line in it. Selector = 1.|[1,Inf]This is a text with a
            new-line in it. Selector > 1.',
                5,
            ],
            // with single-quotes and \n in text
[
                'This is a text with a\\nnew-line in it. Selector = 0.',
                '{0}This is a text with a\\nnew-line in it. Selector = 0.|{1}This is a text with a\\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\\nnew-line in it. Selector > 1.',
                0,
            ],
            // with double-quotes and id split across lines
[
                "This is a text with a\nnew-line in it. Selector = 1.",
                "{0}This is a text with a\nnew-line in it. Selector = 0.|{1}This is a text with a\nnew-line in it. Selector = 1.|[1,Inf]This is a text with a\nnew-line in it. Selector > 1.",
                1,
            ],
            // escape pipe
[
                'This is a text with | in it. Selector = 0.',
                '{0}This is a text with || in it. Selector = 0.|{1}This is a text with || in it. Selector = 1.',
                0,
            ],
            // Empty plural set (2 plural forms) from a .PO file
[
                '',
                '|',
                1,
            ],
            // Empty plural set (3 plural forms) from a .PO file
[
                '',
                '||',
                1,
            ],
            // Floating values
[
                '1.5 liters',
                '%count% liter|%count% liters',
                1.5,
            ],
            [
                '1.5 litre',
                '%count% litre|%count% litres',
                1.5,
                'fr',
            ],
            // Negative values
[
                '-1 degree',
                '%count% degree|%count% degrees',
                -1,
            ],
            [
                '-1 degré',
                '%count% degré|%count% degrés',
                -1,
            ],
            [
                '-1.5 degrees',
                '%count% degree|%count% degrees',
                -1.5,
            ],
            [
                '-1.5 degré',
                '%count% degré|%count% degrés',
                -1.5,
                'fr',
            ],
            [
                '-2 degrees',
                '%count% degree|%count% degrees',
                -2,
            ],
            [
                '-2 degrés',
                '%count% degré|%count% degrés',
                -2,
            ],
        ];
    }
    
    /**
     * @dataProvider failingLangcodes
     */
    public function testFailedLangcodes($nplural, $langCodes) {
        $matrix = $this->generateTestData($langCodes);
        $this->validateMatrix($nplural, $matrix, false);
    }
    
    /**
     * @dataProvider successLangcodes
     */
    public function testLangcodes($nplural, $langCodes) {
        $matrix = $this->generateTestData($langCodes);
        $this->validateMatrix($nplural, $matrix);
    }
    
    /**
     * This array should contain all currently known langcodes.
     *
     * As it is impossible to have this ever complete we should try as hard as possible to have it almost complete.
     */
    public static function successLangcodes() : array {
        return [
            [
                '1',
                [
                    'ay',
                    'bo',
                    'cgg',
                    'dz',
                    'id',
                    'ja',
                    'jbo',
                    'ka',
                    'kk',
                    'km',
                    'ko',
                    'ky',
                ],
            ],
            [
                '2',
                [
                    'nl',
                    'fr',
                    'en',
                    'de',
                    'de_GE',
                    'hy',
                    'hy_AM',
                    'en_US_POSIX',
                ],
            ],
            [
                '3',
                [
                    'be',
                    'bs',
                    'cs',
                    'hr',
                ],
            ],
            [
                '4',
                [
                    'cy',
                    'mt',
                    'sl',
                ],
            ],
            [
                '6',
                [
                    'ar',
                ],
            ],
        ];
    }
    
    /**
     * This array should be at least empty within the near future.
     *
     * This both depends on a complete list trying to add above as understanding
     * the plural rules of the current failing languages.
     *
     * @return array with nplural together with langcodes
     */
    public static function failingLangcodes() : array {
        return [
            [
                '1',
                [
                    'fa',
                ],
            ],
            [
                '2',
                [
                    'jbo',
                ],
            ],
            [
                '3',
                [
                    'cbs',
                ],
            ],
            [
                '4',
                [
                    'gd',
                    'kw',
                ],
            ],
            [
                '5',
                [
                    'ga',
                ],
            ],
        ];
    }
    
    /**
     * We validate only on the plural coverage. Thus the real rules is not tested.
     *
     * @param string $nplural Plural expected
     * @param array  $matrix  Containing langcodes and their plural index values
     */
    protected function validateMatrix(string $nplural, array $matrix, bool $expectSuccess = true) {
        foreach ($matrix as $langCode => $data) {
            $indexes = array_flip($data);
            if ($expectSuccess) {
                $this->assertCount($nplural, $indexes, "Langcode '{$langCode}' has '{$nplural}' plural forms.");
            }
            else {
                $this->assertNotEquals((int) $nplural, \count($indexes), "Langcode '{$langCode}' has '{$nplural}' plural forms.");
            }
        }
    }
    protected function generateTestData($langCodes) {
        $translator = new class  {
            use TranslatorTrait {
                getPluralizationRule as public;
            }

};
        $matrix = [];
        foreach ($langCodes as $langCode) {
            for ($count = 0; $count < 200; ++$count) {
                $plural = $translator->getPluralizationRule($count, $langCode);
                $matrix[$langCode][$count] = $plural;
            }
        }
        return $matrix;
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title
Assert::$count private static property
Assert::anything final public static function
Assert::arrayHasKey final public static function
Assert::assertArrayHasKey final public static function Asserts that an array has a specified key.
Assert::assertArrayNotHasKey final public static function Asserts that an array does not have a specified key.
Assert::assertContains final public static function Asserts that a haystack contains a needle.
Assert::assertContainsEquals final public static function
Assert::assertContainsOnly final public static function Asserts that a haystack contains only values of a given type.
Assert::assertContainsOnlyInstancesOf final public static function Asserts that a haystack contains only instances of a given class name.
Assert::assertCount final public static function Asserts the number of elements of an array, Countable or Traversable.
Assert::assertDirectoryDoesNotExist final public static function Asserts that a directory does not exist.
Assert::assertDirectoryExists final public static function Asserts that a directory exists.
Assert::assertDirectoryIsNotReadable final public static function Asserts that a directory exists and is not readable.
Assert::assertDirectoryIsNotWritable final public static function Asserts that a directory exists and is not writable.
Assert::assertDirectoryIsReadable final public static function Asserts that a directory exists and is readable.
Assert::assertDirectoryIsWritable final public static function Asserts that a directory exists and is writable.
Assert::assertDoesNotMatchRegularExpression final public static function Asserts that a string does not match a given regular expression.
Assert::assertEmpty final public static function Asserts that a variable is empty.
Assert::assertEquals final public static function Asserts that two variables are equal.
Assert::assertEqualsCanonicalizing final public static function Asserts that two variables are equal (canonicalizing).
Assert::assertEqualsIgnoringCase final public static function Asserts that two variables are equal (ignoring case).
Assert::assertEqualsWithDelta final public static function Asserts that two variables are equal (with delta).
Assert::assertFalse final public static function Asserts that a condition is false.
Assert::assertFileDoesNotExist final public static function Asserts that a file does not exist.
Assert::assertFileEquals final public static function Asserts that the contents of one file is equal to the contents of another
file.
Assert::assertFileEqualsCanonicalizing final public static function Asserts that the contents of one file is equal to the contents of another
file (canonicalizing).
Assert::assertFileEqualsIgnoringCase final public static function Asserts that the contents of one file is equal to the contents of another
file (ignoring case).
Assert::assertFileExists final public static function Asserts that a file exists.
Assert::assertFileIsNotReadable final public static function Asserts that a file exists and is not readable.
Assert::assertFileIsNotWritable final public static function Asserts that a file exists and is not writable.
Assert::assertFileIsReadable final public static function Asserts that a file exists and is readable.
Assert::assertFileIsWritable final public static function Asserts that a file exists and is writable.
Assert::assertFileMatchesFormat final public static function Asserts that a string matches a given format string.
Assert::assertFileMatchesFormatFile final public static function Asserts that a string matches a given format string.
Assert::assertFileNotEquals final public static function Asserts that the contents of one file is not equal to the contents of
another file.
Assert::assertFileNotEqualsCanonicalizing final public static function Asserts that the contents of one file is not equal to the contents of another
file (canonicalizing).
Assert::assertFileNotEqualsIgnoringCase final public static function Asserts that the contents of one file is not equal to the contents of another
file (ignoring case).
Assert::assertFinite final public static function Asserts that a variable is finite.
Assert::assertGreaterThan final public static function Asserts that a value is greater than another value.
Assert::assertGreaterThanOrEqual final public static function Asserts that a value is greater than or equal to another value.
Assert::assertInfinite final public static function Asserts that a variable is infinite.
Assert::assertInstanceOf final public static function Asserts that a variable is of a given type.
Assert::assertIsArray final public static function Asserts that a variable is of type array.
Assert::assertIsBool final public static function Asserts that a variable is of type bool.
Assert::assertIsCallable final public static function Asserts that a variable is of type callable.
Assert::assertIsClosedResource final public static function Asserts that a variable is of type resource and is closed.
Assert::assertIsFloat final public static function Asserts that a variable is of type float.
Assert::assertIsInt final public static function Asserts that a variable is of type int.
Assert::assertIsIterable final public static function Asserts that a variable is of type iterable.
Assert::assertIsList final public static function
Assert::assertIsNotArray final public static function Asserts that a variable is not of type array.
Assert::assertIsNotBool final public static function Asserts that a variable is not of type bool.
Assert::assertIsNotCallable final public static function Asserts that a variable is not of type callable.
Assert::assertIsNotClosedResource final public static function Asserts that a variable is not of type resource.
Assert::assertIsNotFloat final public static function Asserts that a variable is not of type float.
Assert::assertIsNotInt final public static function Asserts that a variable is not of type int.
Assert::assertIsNotIterable final public static function Asserts that a variable is not of type iterable.
Assert::assertIsNotNumeric final public static function Asserts that a variable is not of type numeric.
Assert::assertIsNotObject final public static function Asserts that a variable is not of type object.
Assert::assertIsNotReadable final public static function Asserts that a file/dir exists and is not readable.
Assert::assertIsNotResource final public static function Asserts that a variable is not of type resource.
Assert::assertIsNotScalar final public static function Asserts that a variable is not of type scalar.
Assert::assertIsNotString final public static function Asserts that a variable is not of type string.
Assert::assertIsNotWritable final public static function Asserts that a file/dir exists and is not writable.
Assert::assertIsNumeric final public static function Asserts that a variable is of type numeric.
Assert::assertIsObject final public static function Asserts that a variable is of type object.
Assert::assertIsReadable final public static function Asserts that a file/dir is readable.
Assert::assertIsResource final public static function Asserts that a variable is of type resource.
Assert::assertIsScalar final public static function Asserts that a variable is of type scalar.
Assert::assertIsString final public static function Asserts that a variable is of type string.
Assert::assertIsWritable final public static function Asserts that a file/dir exists and is writable.
Assert::assertJson final public static function Asserts that a string is a valid JSON string.
Assert::assertJsonFileEqualsJsonFile final public static function Asserts that two JSON files are equal.
Assert::assertJsonFileNotEqualsJsonFile final public static function Asserts that two JSON files are not equal.
Assert::assertJsonStringEqualsJsonFile final public static function Asserts that the generated JSON encoded object and the content of the given file are equal.
Assert::assertJsonStringEqualsJsonString final public static function Asserts that two given JSON encoded objects or arrays are equal.
Assert::assertJsonStringNotEqualsJsonFile final public static function Asserts that the generated JSON encoded object and the content of the given file are not equal.
Assert::assertJsonStringNotEqualsJsonString final public static function Asserts that two given JSON encoded objects or arrays are not equal.
Assert::assertLessThan final public static function Asserts that a value is smaller than another value.
Assert::assertLessThanOrEqual final public static function Asserts that a value is smaller than or equal to another value.
Assert::assertMatchesRegularExpression final public static function Asserts that a string matches a given regular expression.
Assert::assertNan final public static function Asserts that a variable is nan.
Assert::assertNotContains final public static function Asserts that a haystack does not contain a needle.
Assert::assertNotContainsEquals final public static function
Assert::assertNotContainsOnly final public static function Asserts that a haystack does not contain only values of a given type.
Assert::assertNotCount final public static function Asserts the number of elements of an array, Countable or Traversable.
Assert::assertNotEmpty final public static function Asserts that a variable is not empty.
Assert::assertNotEquals final public static function Asserts that two variables are not equal.
Assert::assertNotEqualsCanonicalizing final public static function Asserts that two variables are not equal (canonicalizing).
Assert::assertNotEqualsIgnoringCase final public static function Asserts that two variables are not equal (ignoring case).
Assert::assertNotEqualsWithDelta final public static function Asserts that two variables are not equal (with delta).
Assert::assertNotFalse final public static function Asserts that a condition is not false.
Assert::assertNotInstanceOf final public static function Asserts that a variable is not of a given type.
Assert::assertNotNull final public static function Asserts that a variable is not null.
Assert::assertNotSame final public static function Asserts that two variables do not have the same type and value.
Used on objects, it asserts that two variables do not reference
the same object.
Assert::assertNotSameSize final public static function Assert that the size of two arrays (or `Countable` or `Traversable` objects)
is not the same.
Assert::assertNotTrue final public static function Asserts that a condition is not true.
Assert::assertNull final public static function Asserts that a variable is null.
Assert::assertObjectEquals final public static function
Assert::assertObjectHasProperty final public static function Asserts that an object has a specified property.
Assert::assertObjectNotHasProperty final public static function Asserts that an object does not have a specified property.
Assert::assertSame final public static function Asserts that two variables have the same type and value.
Used on objects, it asserts that two variables reference
the same object.
Assert::assertSameSize final public static function Assert that the size of two arrays (or `Countable` or `Traversable` objects)
is the same.
Assert::assertStringContainsString final public static function
Assert::assertStringContainsStringIgnoringCase final public static function
Assert::assertStringContainsStringIgnoringLineEndings final public static function
Assert::assertStringEndsNotWith final public static function Asserts that a string ends not with a given suffix.
Assert::assertStringEndsWith final public static function Asserts that a string ends with a given suffix.
Assert::assertStringEqualsFile final public static function Asserts that the contents of a string is equal
to the contents of a file.
Assert::assertStringEqualsFileCanonicalizing final public static function Asserts that the contents of a string is equal
to the contents of a file (canonicalizing).
Assert::assertStringEqualsFileIgnoringCase final public static function Asserts that the contents of a string is equal
to the contents of a file (ignoring case).
Assert::assertStringEqualsStringIgnoringLineEndings final public static function Asserts that two strings are equal except for line endings.
Assert::assertStringMatchesFormat final public static function Asserts that a string matches a given format string.
Assert::assertStringMatchesFormatFile final public static function Asserts that a string matches a given format file.
Assert::assertStringNotContainsString final public static function
Assert::assertStringNotContainsStringIgnoringCase final public static function
Assert::assertStringNotEqualsFile final public static function Asserts that the contents of a string is not equal
to the contents of a file.
Assert::assertStringNotEqualsFileCanonicalizing final public static function Asserts that the contents of a string is not equal
to the contents of a file (canonicalizing).
Assert::assertStringNotEqualsFileIgnoringCase final public static function Asserts that the contents of a string is not equal
to the contents of a file (ignoring case).
Assert::assertStringNotMatchesFormat Deprecated final public static function Asserts that a string does not match a given format string.
Assert::assertStringNotMatchesFormatFile Deprecated final public static function Asserts that a string does not match a given format string.
Assert::assertStringStartsNotWith final public static function Asserts that a string starts not with a given prefix.
Assert::assertStringStartsWith final public static function Asserts that a string starts with a given prefix.
Assert::assertThat final public static function Evaluates a PHPUnit\Framework\Constraint matcher object.
Assert::assertTrue final public static function Asserts that a condition is true.
Assert::assertXmlFileEqualsXmlFile final public static function Asserts that two XML files are equal.
Assert::assertXmlFileNotEqualsXmlFile final public static function Asserts that two XML files are not equal.
Assert::assertXmlStringEqualsXmlFile final public static function Asserts that two XML documents are equal.
Assert::assertXmlStringEqualsXmlString final public static function Asserts that two XML documents are equal.
Assert::assertXmlStringNotEqualsXmlFile final public static function Asserts that two XML documents are not equal.
Assert::assertXmlStringNotEqualsXmlString final public static function Asserts that two XML documents are not equal.
Assert::callback final public static function @psalm-template CallbackInput of mixed
Assert::containsEqual final public static function
Assert::containsIdentical final public static function
Assert::containsOnly final public static function
Assert::containsOnlyInstancesOf final public static function
Assert::countOf final public static function
Assert::directoryExists final public static function
Assert::equalTo final public static function
Assert::equalToCanonicalizing final public static function
Assert::equalToIgnoringCase final public static function
Assert::equalToWithDelta final public static function
Assert::fail final public static function Fails a test with the given message.
Assert::fileExists final public static function
Assert::getCount final public static function Return the current assertion count.
Assert::greaterThan final public static function
Assert::greaterThanOrEqual final public static function
Assert::identicalTo final public static function
Assert::isEmpty final public static function
Assert::isFalse final public static function
Assert::isFinite final public static function
Assert::isInfinite final public static function
Assert::isInstanceOf final public static function
Assert::isJson final public static function
Assert::isList final public static function
Assert::isNan final public static function
Assert::isNativeType private static function
Assert::isNull final public static function
Assert::isReadable final public static function
Assert::isTrue final public static function
Assert::isType final public static function @psalm-param &#039;array&#039;|&#039;boolean&#039;|&#039;bool&#039;|&#039;double&#039;|&#039;float&#039;|&#039;integer&#039;|&#039;int&#039;|&#039;null&#039;|&#039;numeric&#039;|&#039;object&#039;|&#039;real&#039;|&#039;resource&#039;|&#039;resource…
Assert::isWritable final public static function
Assert::lessThan final public static function
Assert::lessThanOrEqual final public static function
Assert::logicalAnd final public static function
Assert::logicalNot final public static function
Assert::logicalOr final public static function
Assert::logicalXor final public static function
Assert::markTestIncomplete final public static function Mark the test as incomplete.
Assert::markTestSkipped final public static function Mark the test as skipped.
Assert::matches final public static function
Assert::matchesRegularExpression final public static function
Assert::objectEquals final public static function
Assert::resetCount final public static function Reset the assertion counter.
Assert::stringContains final public static function
Assert::stringEndsWith final public static function @psalm-param non-empty-string $suffix
Assert::stringEqualsStringIgnoringLineEndings final public static function
Assert::stringStartsWith final public static function @psalm-param non-empty-string $prefix
TestCase::$backupGlobals private property
TestCase::$backupGlobalsExcludeList private property @psalm-var list&lt;string&gt;
TestCase::$backupStaticProperties private property
TestCase::$backupStaticPropertiesExcludeList private property @psalm-var array&lt;string,list&lt;class-string&gt;&gt;
TestCase::$customComparators private property @psalm-var list&lt;Comparator&gt;
TestCase::$data private property
TestCase::$dataName private property
TestCase::$dependencies private property @psalm-var list&lt;ExecutionOrderDependency&gt;
TestCase::$dependencyInput private property
TestCase::$doesNotPerformAssertions private property
TestCase::$expectedException private property
TestCase::$expectedExceptionCode private property
TestCase::$expectedExceptionMessage private property
TestCase::$expectedExceptionMessageRegExp private property
TestCase::$failureTypes private property @psalm-var array&lt;class-string, true&gt;
TestCase::$groups private property @psalm-var list&lt;string&gt;
TestCase::$iniSettings private property @psalm-var array&lt;string,string&gt;
TestCase::$inIsolation private property
TestCase::$locale private property
TestCase::$mockObjects private property @psalm-var list&lt;MockObjectInternal&gt;
TestCase::$name private property @psalm-var non-empty-string
TestCase::$numberOfAssertionsPerformed private property
TestCase::$output private property
TestCase::$outputBufferingActive private property
TestCase::$outputBufferingLevel private property
TestCase::$outputExpectedRegex private property
TestCase::$outputExpectedString private property
TestCase::$outputRetrievedForAssertion private property
TestCase::$preserveGlobalState private property
TestCase::$providedTests private property @psalm-var list&lt;ExecutionOrderDependency&gt;
TestCase::$registerMockObjectsFromTestArgumentsRecursively private property
TestCase::$runClassInSeparateProcess private property
TestCase::$runTestInSeparateProcess private property
TestCase::$snapshot private property
TestCase::$status private property
TestCase::$testResult private property
TestCase::$testValueObjectForEvents private property
TestCase::$wasPrepared private property
TestCase::addToAssertionCount final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::any final public static function Returns a matcher that matches when the method is executed
zero or more times.
TestCase::assertPostConditions protected function Performs assertions shared by all tests of a test case.
TestCase::assertPreConditions protected function Performs assertions shared by all tests of a test case.
TestCase::atLeast final public static function Returns a matcher that matches when the method is executed
at least N times.
TestCase::atLeastOnce final public static function Returns a matcher that matches when the method is executed at least once.
TestCase::atMost final public static function Returns a matcher that matches when the method is executed
at most N times.
TestCase::checkRequirements private function
TestCase::cleanupIniSettings private function
TestCase::cleanupLocaleSettings private function
TestCase::compareGlobalStateSnapshotPart private function
TestCase::compareGlobalStateSnapshots private function
TestCase::count final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::createConfiguredMock protected function Creates (and configures) a mock object for the specified interface or class.
TestCase::createConfiguredStub final protected static function Creates (and configures) a test stub for the specified interface or class.
TestCase::createGlobalStateSnapshot private function
TestCase::createMock protected function Creates a mock object for the specified interface or class.
TestCase::createMockForIntersectionOfInterfaces protected function @psalm-param list&lt;class-string&gt; $interfaces
TestCase::createPartialMock protected function Creates a partial mock object for the specified interface or class.
TestCase::createStub protected static function Creates a test stub for the specified interface or class.
TestCase::createStubForIntersectionOfInterfaces protected static function @psalm-param list&lt;class-string&gt; $interfaces
TestCase::createTestProxy Deprecated protected function Creates a test proxy for the specified class.
TestCase::dataName final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::dataSetAsString final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::dataSetAsStringWithData final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::dependencyInput final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::doesNotPerformAssertions final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::exactly final public static function Returns a matcher that matches when the method is executed
exactly $count times.
TestCase::expectedExceptionWasNotRaised private function
TestCase::expectException final public function @psalm-param class-string&lt;Throwable&gt; $exception
TestCase::expectExceptionCode final public function
TestCase::expectExceptionMessage final public function
TestCase::expectExceptionMessageMatches final public function
TestCase::expectExceptionObject final public function Sets up an expectation for an exception to be raised by the code under test.
Information for expected exception class, expected exception message, and
expected exception code are retrieved from a given Exception object.
TestCase::expectNotToPerformAssertions final public function
TestCase::expectOutputRegex final public function
TestCase::expectOutputString final public function
TestCase::expectsOutput final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::getActualOutputForAssertion final public function
TestCase::getMockBuilder final public function Returns a builder object to create mock objects using a fluent interface.
TestCase::getMockForAbstractClass Deprecated protected function Creates a mock object for the specified abstract class with all abstract
methods of the class mocked. Concrete methods are not mocked by default.
To mock concrete methods, use the 7th parameter ($mockedMethods).
TestCase::getMockForTrait Deprecated protected function Creates a mock object for the specified trait with all abstract methods
of the trait mocked. Concrete methods to mock can be specified with the
`$mockedMethods` parameter.
TestCase::getMockFromWsdl Deprecated protected function Creates a mock object based on the given WSDL file.
TestCase::getObjectForTrait Deprecated protected function Creates an object that uses the specified trait.
TestCase::groups final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::handleDependencies private function
TestCase::hasDependencyInput final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::hasExpectationOnOutput private function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::hasUnexpectedOutput final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::iniSet Deprecated protected function This method is a wrapper for the ini_set() function that automatically
resets the modified php.ini setting to its original value after the
test is run.
TestCase::invokeAfterClassHookMethods private function @codeCoverageIgnore
TestCase::invokeAfterTestHookMethods private function
TestCase::invokeBeforeClassHookMethods private function @codeCoverageIgnore
TestCase::invokeBeforeTestHookMethods private function
TestCase::invokeHookMethods private function @psalm-param list&lt;non-empty-string&gt; $hookMethods
@psalm-param…
TestCase::invokePostConditionHookMethods private function
TestCase::invokePreConditionHookMethods private function
TestCase::isCallableTestMethod private function
TestCase::isRegisteredFailure private function
TestCase::LOCALE_CATEGORIES private constant
TestCase::markErrorForInvalidDependency private function
TestCase::markSkippedForMissingDependency private function
TestCase::methodDoesNotExistOrIsDeclaredInTestCase private function
TestCase::name final public function @psalm-return non-empty-string
TestCase::nameWithDataSet final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::never final public static function Returns a matcher that matches when the method is never executed.
TestCase::numberOfAssertionsPerformed final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::once final public static function Returns a matcher that matches when the method is executed exactly once.
TestCase::onConsecutiveCalls Deprecated final public static function @codeCoverageIgnore
TestCase::onNotSuccessfulTest protected function This method is called when a test method did not execute successfully.
TestCase::output final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::performAssertionsOnOutput private function
TestCase::providedData final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::provides final public function @psalm-return list&lt;ExecutionOrderDependency&gt; Overrides Reorderable::provides
TestCase::registerComparator final protected function
TestCase::registerFailureType final protected function @psalm-param class-string $classOrInterface
TestCase::registerMockObject final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::registerMockObjectsFromTestArguments private function
TestCase::registerMockObjectsFromTestArgumentsRecursively final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::requirementsNotSatisfied private function
TestCase::requires final public function @psalm-return list&lt;ExecutionOrderDependency&gt; Overrides Reorderable::requires
TestCase::restoreGlobalState private function
TestCase::result final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::returnArgument Deprecated final public static function @codeCoverageIgnore
TestCase::returnCallback Deprecated final public static function @codeCoverageIgnore
TestCase::returnSelf Deprecated final public static function @codeCoverageIgnore
TestCase::returnValue Deprecated final public static function @codeCoverageIgnore
TestCase::returnValueMap Deprecated final public static function @codeCoverageIgnore
TestCase::run final public function @internal This method is not covered by the backward compatibility promise for PHPUnit Overrides Test::run
TestCase::runBare final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::runTest protected function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setBackupGlobals final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setBackupGlobalsExcludeList final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setBackupStaticProperties final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setBackupStaticPropertiesExcludeList final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setData final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setDependencies final public function @psalm-param list&lt;ExecutionOrderDependency&gt; $dependencies
TestCase::setDependencyInput final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setGroups final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setInIsolation final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setLocale Deprecated protected function This method is a wrapper for the setlocale() function that automatically
resets the locale to its original value after the test is run.
TestCase::setName final public function @psalm-param non-empty-string $name
TestCase::setPreserveGlobalState final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setResult final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setRunClassInSeparateProcess final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setRunTestInSeparateProcess final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::setUpBeforeClass public static function This method is called before the first test of this test class is run.
TestCase::shouldExceptionExpectationsBeVerified private function
TestCase::shouldInvocationMockerBeReset private function
TestCase::shouldRunInSeparateProcess private function
TestCase::size final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::snapshotGlobalState private function
TestCase::sortId final public function @internal This method is not covered by the backward compatibility promise for PHPUnit Overrides Reorderable::sortId
TestCase::startOutputBuffering private function
TestCase::status final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::stopOutputBuffering private function
TestCase::tearDownAfterClass public static function This method is called after the last test of this test class is run.
TestCase::throwException final public static function
TestCase::toString public function Returns a string representation of the test case. Overrides SelfDescribing::toString
TestCase::transformException protected function
TestCase::unregisterCustomComparators private function
TestCase::usesDataProvider final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::valueObjectForEvents final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::verifyExceptionExpectations private function
TestCase::verifyMockObjects private function
TestCase::wasPrepared final public function @internal This method is not covered by the backward compatibility promise for PHPUnit
TestCase::__construct public function @psalm-param non-empty-string $name
TranslatorTest::$defaultLocale private property
TranslatorTest::failingLangcodes public static function This array should be at least empty within the near future.
TranslatorTest::generateTestData protected function
TranslatorTest::getChooseTests public static function
TranslatorTest::getInterval public static function
TranslatorTest::getNonMatchingMessages public static function
TranslatorTest::getTransChoiceTests public static function
TranslatorTest::getTranslator public function
TranslatorTest::getTransTests public static function
TranslatorTest::setUp protected function This method is called before each test. Overrides TestCase::setUp
TranslatorTest::successLangcodes public static function This array should contain all currently known langcodes.
TranslatorTest::tearDown protected function This method is called after each test. Overrides TestCase::tearDown
TranslatorTest::testChoose public function @dataProvider getChooseTests
TranslatorTest::testFailedLangcodes public function @dataProvider failingLangcodes
TranslatorTest::testGetLocaleReturnsDefaultLocaleIfNotSet public function @requires extension intl
TranslatorTest::testGetSetLocale public function
TranslatorTest::testInterval public function @dataProvider getInterval
TranslatorTest::testLangcodes public function @dataProvider successLangcodes
TranslatorTest::testReturnMessageIfExactlyOneStandardRuleIsGiven public function
TranslatorTest::testThrowExceptionIfMatchingMessageCannotBeFound public function @dataProvider getNonMatchingMessages
TranslatorTest::testTrans public function @dataProvider getTransTests
TranslatorTest::testTransChoiceWithDefaultLocale public function @requires extension intl
TranslatorTest::testTransChoiceWithEnUsPosix public function @dataProvider getTransChoiceTests
TranslatorTest::testTransChoiceWithExplicitLocale public function @dataProvider getTransChoiceTests
TranslatorTest::validateMatrix protected function We validate only on the plural coverage. Thus the real rules is not tested.
RSS feed
Powered by Drupal