Added some tests for the database setting repository

This commit is contained in:
kirkbushell 2015-09-28 15:34:32 +01:00
parent b93d5570d0
commit a388fe7883
3 changed files with 36 additions and 3 deletions

View File

@ -4,4 +4,4 @@ composer.phar
Thumbs.db
tests/_output/*
.vagrant
.idea/
.idea/*

View File

@ -33,10 +33,10 @@
"dflydev/fig-cookies": "^1.0",
"symfony/console": "^2.7",
"symfony/yaml": "^2.7",
"doctrine/dbal": "^2.5",
"mockery/mockery": "^0.9.4"
"doctrine/dbal": "^2.5"
},
"require-dev": {
"mockery/mockery": "^0.9.4",
"squizlabs/php_codesniffer": "2.*",
"phpunit/phpunit": "^4.8"
},

View File

@ -0,0 +1,33 @@
<?php
namespace tests\Flarum\Core\Settings;
use Flarum\Core\Settings\DatabaseSettingsRepository;
use Illuminate\Database\ConnectionInterface;
use Mockery as m;
use tests\Test\TestCase;
class DatabaseSettingsRepositoryTest extends TestCase
{
private $connection;
private $repository;
public function init()
{
$this->connection = m::mock(ConnectionInterface::class);
$this->repository = new DatabaseSettingsRepository($this->connection);
}
public function test_requesting_an_existing_setting_should_return_its_value()
{
$this->connection->shouldReceive("table->where->pluck")->andReturn('value');
$this->assertEquals('value', $this->repository->get('key'));
}
public function test_non_existent_setting_values_should_return_null()
{
$this->connection->shouldReceive("table->where->pluck")->andReturn(null);
$this->assertEquals('default', $this->repository->get('key', 'default'));
}
}