Skip to content

Commit

Permalink
Add FailingProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 7, 2024
1 parent 358f74f commit e631579
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Provider/FailingProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ICanBoogie\CLDR\Provider;

use ICanBoogie\CLDR\Provider;
use LogicException;

/**
* A {@see Provider} that fails to provide any path.
*
* This provider is useful when you want to restrict the usage of the repository to warmed-up data.
*/
final class FailingProvider implements Provider
{
public function provide(string $path): array
{
throw new LogicException("Only warmed-up data is available, tried to read from: $path");
}
}
23 changes: 23 additions & 0 deletions tests/Provider/FailingProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Test\ICanBoogie\CLDR\Provider;

use ICanBoogie\CLDR\Provider\FailingProvider;
use LogicException;
use PHPUnit\Framework\TestCase;

/**
* @group static
*/
class FailingProviderTest extends TestCase
{
public function test_provide(): void
{
$sut = new FailingProvider();

$this->expectException(LogicException::class);
$this->expectExceptionMessageMatches("/Only warmed-up data is available/");

$sut->provide("foo");
}
}

0 comments on commit e631579

Please sign in to comment.