-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Adds
StoryblokCollectorTest
(#6)
- Loading branch information
1 parent
69af105
commit 0f6474d
Showing
2 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of sensiolabs-de/storyblok-bundle. | ||
* | ||
* (c) SensioLabs Deutschland <info@sensiolabs.de> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SensioLabs\Storyblok\Bundle\Tests\Unit\DataCollector; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SensioLabs\Storyblok\Bundle\DataCollector\StoryblokCollector; | ||
use SensioLabs\Storyblok\Bundle\Tests\Util\FakerTrait; | ||
use Symfony\Component\HttpClient\MockHttpClient; | ||
use Symfony\Component\HttpClient\Response\JsonMockResponse; | ||
use Symfony\Component\HttpClient\TraceableHttpClient; | ||
|
||
final class StoryblokCollectorTest extends TestCase | ||
{ | ||
use FakerTrait; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function defaults(): void | ||
{ | ||
$client = new TraceableHttpClient(new MockHttpClient()); | ||
$collector = new StoryblokCollector($client); | ||
|
||
self::assertEmpty($collector->getTraces()); | ||
self::assertSame(0, $collector->getRequestCount()); | ||
self::assertSame(0, $collector->getErrorCount()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function getTemplate(): void | ||
{ | ||
self::assertSame('@Storyblok/data_collector.html.twig', StoryblokCollector::getTemplate()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function lateCollect(): void | ||
{ | ||
$client = new TraceableHttpClient(new MockHttpClient([ | ||
new JsonMockResponse(['hello' => 'there'], ['http_code' => 200]), | ||
])); | ||
|
||
$client->request('GET', 'https://example.com'); | ||
|
||
$collector = new StoryblokCollector($client); | ||
|
||
$collector->lateCollect(); | ||
|
||
self::assertCount(1, $collector->getTraces()); | ||
self::assertSame(1, $collector->getRequestCount()); | ||
self::assertSame(0, $collector->getErrorCount()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function reset(): void | ||
{ | ||
$client = new TraceableHttpClient(new MockHttpClient([ | ||
new JsonMockResponse(['hello' => 'there'], ['http_code' => 200]), | ||
])); | ||
|
||
$client->request('GET', 'https://example.com'); | ||
|
||
$collector = new StoryblokCollector($client); | ||
|
||
$collector->lateCollect(); | ||
|
||
self::assertCount(1, $collector->getTraces()); | ||
self::assertSame(1, $collector->getRequestCount()); | ||
self::assertSame(0, $collector->getErrorCount()); | ||
|
||
$collector->reset(); | ||
|
||
self::assertEmpty($collector->getTraces()); | ||
self::assertSame(0, $collector->getRequestCount()); | ||
self::assertSame(0, $collector->getErrorCount()); | ||
} | ||
} |