4
4
5
5
namespace WyriHaximus \Tests \TestUtilities ;
6
6
7
+ use PHPUnit \Framework \Attributes \DataProvider ;
7
8
use PHPUnit \Framework \Attributes \Test ;
8
- use RuntimeException ;
9
9
use WyriHaximus \TestUtilities \TestCase ;
10
10
11
- use function chmod ;
12
11
use function func_get_args ;
13
12
use function random_int ;
14
13
use function Safe \file_get_contents ;
19
18
use function substr ;
20
19
use function sys_get_temp_dir ;
21
20
use function time ;
22
- use function touch ;
23
21
use function uniqid ;
24
22
25
23
use const DIRECTORY_SEPARATOR ;
@@ -55,12 +53,14 @@ public static function provideTemporaryDirectory(): iterable
55
53
}
56
54
}
57
55
58
- public function testRecursiveDirectoryCreation (): void
56
+ #[Test]
57
+ public function recursiveDirectoryCreation (): void
59
58
{
60
59
static ::assertFileExists ($ this ->getTmpDir ());
61
60
}
62
61
63
- /** @dataProvider provideTemporaryDirectory */
62
+ #[Test]
63
+ #[DataProvider('provideTemporaryDirectory ' )]
64
64
public function testTemporaryDirectoryAndGetFilesInDirectory (string $ int ): void
65
65
{
66
66
static ::assertTrue (strtoupper (substr (PHP_OS , TestCase::WIN_START , TestCase::WIN_END )) === 'WIN ' ? strpos (TestCase::WINDOWS_TEMP_DIR_PREFIX , sys_get_temp_dir ()) === 0 : strpos ($ this ->getTmpDir (), sys_get_temp_dir ()) === 0 );
@@ -81,12 +81,14 @@ public function testTemporaryDirectoryAndGetFilesInDirectory(string $int): void
81
81
}
82
82
}
83
83
84
- /** @dataProvider provideTrueFalse */
85
- public function testTrueOrFalse (bool $ bool ): void
84
+ #[Test]
85
+ #[DataProvider('provideTrueFalse ' )]
86
+ public function trueOrFalse (bool $ bool ): void
86
87
{
87
88
static ::assertCount (1 , func_get_args ());
88
89
}
89
90
91
+ #[Test]
90
92
public function testTrueAndFalse (): void
91
93
{
92
94
static ::assertSame (
@@ -95,53 +97,33 @@ public function testTrueAndFalse(): void
95
97
);
96
98
}
97
99
98
- public function testGetSysTempDir (): void
100
+ #[Test]
101
+ public function successGetSysTempDir (): void
99
102
{
100
103
self ::assertFileExists ($ this ->getSysTempDir ());
101
104
}
102
105
103
- public function testWaitUntilTheNextSecond (): void
106
+ #[Test]
107
+ public function successWaitUntilTheNextSecond (): void
104
108
{
105
109
$ now = time ();
106
110
static ::waitUntilTheNextSecond ();
107
111
self ::assertSame ($ now + 1 , time ());
108
112
}
109
113
110
- public function testRmDir (): void
111
- {
112
- $ tmpDir = $ this ->getSysTempDir () .
113
- DIRECTORY_SEPARATOR .
114
- 'p-a-c-t- ' .
115
- uniqid () .
116
- DIRECTORY_SEPARATOR ;
117
-
118
- mkdir ($ tmpDir );
119
-
120
- self ::assertDirectoryExists ($ tmpDir );
121
- $ this ->rmdir ($ tmpDir );
122
- self ::assertDirectoryDoesNotExist ($ tmpDir );
123
- }
124
-
125
114
#[Test]
126
- public function failRmDir (): void
115
+ public function successRmDir (): void
127
116
{
128
117
$ tmpDir = $ this ->getSysTempDir () .
129
118
DIRECTORY_SEPARATOR .
130
119
'p-a-c-t- ' .
131
120
uniqid () .
132
121
DIRECTORY_SEPARATOR ;
133
122
134
- self ::expectException (RuntimeException::class);
135
- self ::expectExceptionMessage ('Error deleting directory: ' . $ tmpDir . ' with error: rmdir( ' . $ tmpDir . '): Directory not empty ' );
136
-
137
123
mkdir ($ tmpDir );
138
- touch ($ tmpDir . '__FILE__ ' );
139
124
140
125
self ::assertDirectoryExists ($ tmpDir );
141
- self ::assertFileExists ($ tmpDir . '__FILE__ ' );
142
-
143
- chmod ($ tmpDir , 0444 );
144
-
145
126
$ this ->rmdir ($ tmpDir );
127
+ self ::assertDirectoryDoesNotExist ($ tmpDir );
146
128
}
147
129
}
0 commit comments