mirror of
https://github.com/flarum/core.git
synced 2025-08-03 23:17:43 +02:00
Removed phpsec as the testing library, added phpunit and converted the first spec test to phpunit format. Also added mockery.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
namespace tests\Flarum\Core\Settings;
|
||||
|
||||
use Flarum\Core\Settings\MemoryCacheSettingsRepository;
|
||||
use Flarum\Core\Settings\SettingsRepository;
|
||||
use Mockery as m;
|
||||
use tests\Test\TestCase;
|
||||
|
||||
class MemoryCacheSettingsRepositoryTest extends TestCase
|
||||
{
|
||||
private $baseRepository;
|
||||
private $repository;
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->baseRepository = m::mock(SettingsRepository::class);
|
||||
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository);
|
||||
}
|
||||
|
||||
public function test_it_should_return_all_settings_when_not_cached()
|
||||
{
|
||||
$this->baseRepository->shouldReceive('all')->once()->andReturn(['key' => 'value']);
|
||||
|
||||
$this->assertEquals(['key' => 'value'], $this->repository->all());
|
||||
$this->assertEquals(['key' => 'value'], $this->repository->all()); // Assert twice to ensure we hit the cache
|
||||
}
|
||||
|
||||
public function test_it_should_retrieve_a_specific_value()
|
||||
{
|
||||
$this->baseRepository->shouldReceive('all')->once()->andReturn(['key1' => 'value1', 'key2' => 'value2']);
|
||||
|
||||
$this->assertEquals('value2', $this->repository->get('key2'));
|
||||
$this->assertEquals('value2', $this->repository->get('key2')); // Assert twice to ensure we hit the cache
|
||||
}
|
||||
|
||||
public function test_it_should_set_a_key_value_pair()
|
||||
{
|
||||
$this->baseRepository->shouldReceive('set')->once();
|
||||
|
||||
$this->repository->set('key', 'value');
|
||||
|
||||
$this->assertEquals('value', $this->repository->get('key'));
|
||||
}
|
||||
}
|
20
tests/Test/TestCase.php
Normal file
20
tests/Test/TestCase.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace tests\Test;
|
||||
|
||||
use Mockery;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class TestCase extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
Mockery::close();
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
// To be overloaded by children - saves having to do setUp/mockery::close every time
|
||||
}
|
||||
}
|
24
tests/phpunit.xml
Normal file
24
tests/phpunit.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
syntaxCheck="false">
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="all">
|
||||
<directory suffix="Test.php">./</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<php>
|
||||
<env name="APP_ENV" value="testing"/>
|
||||
<env name="CACHE_DRIVER" value="array"/>
|
||||
</php>
|
||||
|
||||
</phpunit>
|
Reference in New Issue
Block a user