/
Php81LanguageFeaturesTest.php
102 lines (83 loc) · 2.17 KB
/
Php81LanguageFeaturesTest.php
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
<?php
namespace test\Mockery;
use DateTime;
use Serializable;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use ReturnTypeWillChange;
/**
* @requires PHP 8.1.0-dev
*/
class Php81LanguageFeaturesTest extends MockeryTestCase
{
/**
* @test
* @group issue/339
*/
public function canMockClassesThatImplementSerializable()
{
$mock = mock("test\Mockery\ClassThatImplementsSerializable");
$this->assertInstanceOf("Serializable", $mock);
}
/** @test */
public function it_can_mock_an_internal_class_with_tentative_return_types()
{
$mock = spy(DateTime::class);
$this->assertSame(0, $mock->getTimestamp());
}
/**
* @test
*/
public function it_can_mock_an_internal_class_with_tentative_union_return_types()
{
$mock = m::mock('PDO');
$this->assertInstanceOf('PDO', $mock);
$mock->shouldReceive('exec')->once();
try {
$this->assertSame(0, $mock->exec('select * from foo.bar'));
} finally {
m::close();
}
}
/** @test */
public function it_can_mock_a_class_with_return_type_will_change_attribute_and_no_return_type()
{
$mock = spy(ReturnTypeWillChangeAttributeNoReturnType::class);
$this->assertNull($mock->getTimestamp());
}
/** @test */
public function it_can_mock_a_class_with_return_type_will_change_attribute_and_wrong_return_type()
{
$mock = spy(ReturnTypeWillChangeAttributeWrongReturnType::class);
$this->assertSame(0.0, $mock->getTimestamp());
}
}
class ClassThatImplementsSerializable implements Serializable
{
public function serialize(): ?string
{
}
public function __serialize(): array
{
}
public function unserialize(string $data): void
{
}
public function __unserialize(array $data): void
{
}
}
class ReturnTypeWillChangeAttributeNoReturnType extends DateTime
{
#[ReturnTypeWillChange]
public function getTimestamp()
{
}
}
class ReturnTypeWillChangeAttributeWrongReturnType extends DateTime
{
#[ReturnTypeWillChange]
public function getTimestamp(): float
{
}
}