2
2
3
3
namespace Integration ;
4
4
5
+ use PHPUnit \Framework \Attributes \DataProvider ;
5
6
use PHPUnit \Framework \Attributes \Group ;
6
7
use PHPUnit \Framework \Attributes \Test ;
7
8
use PHPUnit \Framework \TestCase ;
@@ -15,34 +16,49 @@ public static function setUpBeforeClass(): void
15
16
{
16
17
parent ::setUpBeforeClass ();
17
18
18
- fopen ("outputFile .html " , "w " );
19
+ fopen ("output .html " , "w " );
19
20
}
20
21
21
22
public static function tearDownAfterClass (): void
22
23
{
23
24
parent ::tearDownAfterClass ();
24
- unlink ("outputFile .html " );
25
+ unlink ("output .html " );
25
26
}
26
27
27
28
#[Test]
28
- public function streamAndWriteToFile ()
29
+ #[DataProvider('streamDataProvider ' )]
30
+ public function streamAndWriteToFile ($ output , $ url )
29
31
{
30
- $ url = "https://gist.github.com/rcsofttech85/629b37d483c4796db7bdcb3704067631#file-gistfile1-txt " ;
31
- $ stream = new Stream ($ url , "outputFile.html " );
32
+ $ stream = new Stream ($ url , $ output );
32
33
$ stream ->startStreaming ();
33
34
34
- $ this ->assertGreaterThan (0 , filesize (" outputFile.html " ));
35
- $ this ->assertStringContainsString ('<!DOCTYPE html> ' , file_get_contents (" outputFile.html " ));
36
- $ this ->assertStringContainsString ('</html> ' , file_get_contents (" outputFile.html " ));
35
+ $ this ->assertGreaterThan (0 , filesize ($ output ));
36
+ $ this ->assertStringContainsString ('<!DOCTYPE html> ' , file_get_contents ($ output ));
37
+ $ this ->assertStringContainsString ('</html> ' , file_get_contents ($ output ));
37
38
}
38
39
39
40
#[Test]
40
- public function throwExceptionIfUrlIsInvalid ()
41
+ #[DataProvider('wrongStreamDataProvider ' )]
42
+ public function throwExceptionIfUrlIsInvalid ($ output , $ url )
41
43
{
42
- $ url = "https://gist.github " ;
43
- $ stream = new Stream ($ url , "outputFile.html " );
44
+ $ stream = new Stream ($ url , $ output );
44
45
45
46
$ this ->expectException (StreamException::class);
46
47
$ stream ->startStreaming ();
47
48
}
49
+
50
+ public static function streamDataProvider (): iterable
51
+ {
52
+ yield [
53
+ "output.html " ,
54
+ "https://gist.github.com/rcsofttech85/629b37d483c4796db7bdcb3704067631#file-gistfile1-txt "
55
+ ];
56
+ }
57
+
58
+ public static function wrongStreamDataProvider (): iterable
59
+ {
60
+ yield ["output.html " , "https://gist.github " ];
61
+ }
62
+
63
+
48
64
}
0 commit comments