arjan.top wrote:It won't be OK i think, you are trying to test set and get, none of them is implemented yet
Well, that's sort of the point. It's test-driven so the failing test is our specification for what we have to code. If we're going down the DataStore as a simple container delegating to a persistence layer then what matthijs posted is right.
Let's just establish where we're putting this code first.
In classes/DataStore.php:
Code: Select all
<?php
class DataStore {
public function set($key, $value) {
}
public function get($key) {
}
}
In tests/unit/DataStoreTest.php:
Code: Select all
<?php
require_once dirname(__FILE__) . '/../configure.php';
require_once dirname(__FILE__) . '/../../classes/DataStore.php';
class DataStoreTest extends UnitTestCase {
public function testAddSometingToDataStore() {
$data = new DataStore();
$data->set('foo', 'bar');
$this->assertEqual($data->get('foo'), 'bar');
}
}
And in tests/AllTests.php:
Code: Select all
<?php
require_once dirname(__FILE__) . '/configure.php';
class DataStoreTestSuite extends TestSuite {
public function __construct() {
parent::__construct('All DataStore tests');
$this->addFile(TEST_BASE . '/unit/DataStoreTest.php');
}
}
This produces a failure:
Code: Select all
AllTests.php
1) Equal expectation fails as [NULL] does not match [String: bar] at [/Users/chris/data_store/tests/unit/DataStoreTest.php line 10]
in testAddSomethingToDataStore
in DataStoreTest
in /Users/chris/data_store/tests/unit/DataStoreTest.php
in All DataStore tests
FAILURES!!!
Test cases run: 1/1, Passes: 0, Failures: 1, Exceptions: 0
Before we continue I'd just like to bring something up. The name of the test method... can we improve it? Is it really describing what we're testing?
