File: Php74Test.php

package info (click to toggle)
php-symfony-polyfill 1.33.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 8,520 kB
  • sloc: php: 127,232; makefile: 69
file content (145 lines) | stat: -rw-r--r-- 3,960 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
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
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Polyfill\Tests\Php74;

use PHPUnit\Framework\Attributes\RequiresPhp;
use PHPUnit\Framework\TestCase;

/**
 * @author Ion Bazan <ion.bazan@gmail.com>
 */
class Php74Test extends TestCase
{
    /**
     * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars
     */
    public function testGetMangledObjectVarsOnObject()
    {
        $obj = new B();
        $obj->dyn = 5;
        $obj->{'6'} = 6;

        $this->assertEqualsCanonicalizing([
            "\0".'Symfony\Polyfill\Tests\Php74\B'."\0".'priv' => 4,
            'pub' => 1,
            "\0".'*'."\0".'prot' => 2,
            "\0".'Symfony\Polyfill\Tests\Php74\A'."\0".'priv' => 3,
            'dyn' => 5,
            6 => 6,
        ], get_mangled_object_vars($obj));
    }

    /**
     * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars
     */
    public function testGetMangledObjectVarsOnArrayObject()
    {
        $ao = new AO(['x' => 'y']);
        $ao->dyn = 2;

        $this->assertSame([
            "\0".'Symfony\Polyfill\Tests\Php74\AO'."\0".'priv' => 1,
            'dyn' => 2,
        ], get_mangled_object_vars($ao));
    }

    /**
     * @covers \Symfony\Polyfill\Php74\Php74::get_mangled_object_vars
     *
     * @requires PHP < 8
     */
    #[RequiresPhp('< 8')]
    public function testGetMangledObjectVarsOnNonObject()
    {
        $this->assertNull(@get_mangled_object_vars(0));
        $this->assertNull(@get_mangled_object_vars(true));
        $this->assertNull(@get_mangled_object_vars('string'));
        $this->expectWarning();
        $this->expectWarningMessage('expects parameter 1 to be object');
        get_mangled_object_vars(1);
    }

    /**
     * @covers \Symfony\Polyfill\Php74\Php74::password_algos
     */
    public function testPasswordAlgos()
    {
        $algos = password_algos();

        if (\defined('PASSWORD_BCRYPT')) {
            $this->assertContains(\PASSWORD_BCRYPT, $algos);
        }

        if (\defined('PASSWORD_ARGON2I')) {
            $this->assertContains(\PASSWORD_ARGON2I, $algos);
        }

        if (\defined('PASSWORD_ARGON2ID')) {
            $this->assertContains(\PASSWORD_ARGON2ID, $algos);
        }
    }

    /**
     * @covers \Symfony\Polyfill\Php74\Php74::mb_str_split
     */
    public function testStrSplit()
    {
        $this->assertSame(['한', '국', '어'], mb_str_split('한국어'));
        $this->assertSame(['по', 'бе', 'да'], mb_str_split('победа', 2));
        $this->assertSame(['źre', 'bię'], mb_str_split('źrebię', 3));
        $this->assertSame(['źr', 'ebi', 'ę'], mb_str_split('źrebię', 3, 'ASCII'));
        $this->assertSame(['alpha', 'bet'], mb_str_split('alphabet', 5));
        $this->assertSame(['e', '́', '💩', '𐍈'], mb_str_split('é💩𐍈', 1, 'UTF-8'));
    }

    /**
     * @covers \Symfony\Polyfill\Php74\Php74::mb_str_split
     *
     * @requires PHP < 8
     */
    #[RequiresPhp('< 8')]
    public function testStrSplitWithInvalidValues()
    {
        $this->assertSame([], mb_str_split('', 1, 'UTF-8'));
        $this->assertFalse(@mb_str_split('победа', 0));
        $this->assertNull(@mb_str_split([], 0));

        $this->expectWarning();
        $this->expectWarningMessage('The length of each segment must be greater than zero');
        mb_str_split('победа', 0);
    }
}

class A
{
    public $pub = 1;
    protected $prot = 2;
    private $priv = 3;
}

#[\AllowDynamicProperties]
class B extends A
{
    private $priv = 4;
}

#[\AllowDynamicProperties]
class AO extends \ArrayObject
{
    private $priv = 1;

    #[\ReturnTypeWillChange]
    public function getFlags()
    {
        return self::ARRAY_AS_PROPS | self::STD_PROP_LIST;
    }
}