Skip to content

Commit ebfcaf7

Browse files
authored
Merge pull request #5 from rcsofttech85/tests
add data provider for stream test
2 parents 821a25a + 91878b7 commit ebfcaf7

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

tests/Integration/StreamTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Integration;
44

5+
use PHPUnit\Framework\Attributes\DataProvider;
56
use PHPUnit\Framework\Attributes\Group;
67
use PHPUnit\Framework\Attributes\Test;
78
use PHPUnit\Framework\TestCase;
@@ -15,34 +16,49 @@ public static function setUpBeforeClass(): void
1516
{
1617
parent::setUpBeforeClass();
1718

18-
fopen("outputFile.html", "w");
19+
fopen("output.html", "w");
1920
}
2021

2122
public static function tearDownAfterClass(): void
2223
{
2324
parent::tearDownAfterClass();
24-
unlink("outputFile.html");
25+
unlink("output.html");
2526
}
2627

2728
#[Test]
28-
public function streamAndWriteToFile()
29+
#[DataProvider('streamDataProvider')]
30+
public function streamAndWriteToFile($output, $url)
2931
{
30-
$url = "https://gist.github.com/rcsofttech85/629b37d483c4796db7bdcb3704067631#file-gistfile1-txt";
31-
$stream = new Stream($url, "outputFile.html");
32+
$stream = new Stream($url, $output);
3233
$stream->startStreaming();
3334

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));
3738
}
3839

3940
#[Test]
40-
public function throwExceptionIfUrlIsInvalid()
41+
#[DataProvider('wrongStreamDataProvider')]
42+
public function throwExceptionIfUrlIsInvalid($output, $url)
4143
{
42-
$url = "https://gist.github";
43-
$stream = new Stream($url, "outputFile.html");
44+
$stream = new Stream($url, $output);
4445

4546
$this->expectException(StreamException::class);
4647
$stream->startStreaming();
4748
}
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+
4864
}

0 commit comments

Comments
 (0)