Skip to content

Commit

Permalink
Use ICANBOOGIE_CLDR_MODE to run test in static mode (no web calls)
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 7, 2024
1 parent 0c485d0 commit f16bbea
Show file tree
Hide file tree
Showing 2 changed files with 29 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 RuntimeException;

/**
* 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 RuntimeException("Only warmed up data is available, tried to read from: $path");
}
}
10 changes: 10 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ICanBoogie\CLDR\Cache\RedisCache;
use ICanBoogie\CLDR\Cache\RuntimeCache;
use ICanBoogie\CLDR\Provider\CachedProvider;
use ICanBoogie\CLDR\Provider\FailingProvider;
use ICanBoogie\CLDR\Provider\WebProvider;
use Redis;

Expand All @@ -37,6 +38,15 @@ function create_provider(): Provider
return $provider;
}

if (getenv('ICANBOOGIE_CLDR_MODE') === 'static') {
echo "*** RUNNING TESTS IN STATIC MODE\n";

return $provider = new CachedProvider(
new FailingProvider(),
new FileCache(CACHE_DIR),
);
}

$redis = new Redis();
$host = getenv('ICANBOOGIE_CLDR_REDIS_HOST');
$port = getenv('ICANBOOGIE_CLDR_REDIS_PORT');
Expand Down

0 comments on commit f16bbea

Please sign in to comment.