Page 7 of 15
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 9:51 am
by Chris Corbyn

I'm just enjoying the coding.
I'm off to bed, but I'll leave you with this bug to fix

Make sure error reporting is at least E_ALL (I added it to tests/configure.php).
Code: Select all
public function testGetReturnsNullForUndefinedValues() {
$this->assertNull($this->_dataStore->get('foo'),
'%s: NULL should be returned because the value is not present'
);
}
Code: Select all
AllTests.php
Exception 1!
Unexpected PHP error [Undefined index: foo] severity [8] in [/Users/d11wtq/data_store/classes/DataStore.php line 20]
in testGetReturnsNullForUndefinedValues
in DataStoreTest
in /Users/d11wtq/data_store/tests/unit/DataStoreTest.php
in All DataStore tests
FAILURES!!!
Test cases run: 1/1, Passes: 11, Failures: 0, Exceptions: 1
I'm open to alternative to returning NULL too if you guys think it's a bad idea. Will see what's happenin' tomorrow.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 9:59 am
by matthijs
Maybe
Code: Select all
public function get($key) {
return isset($this->_store[$key]) ? $this->_store[$key] : null;
}
Have a good night

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 10:10 am
by Chris Corbyn
matthijs wrote:Maybe
Code: Select all
public function get($key) {
return isset($this->_store[$key]) ? $this->_store[$key] : null;
}
Have a good night

Not gone to bed yet

That's a lie. I'm in bed on my Macbook

We have method who's responsibility it is to determine if the value exists. Could we maybe drop the isset() in favour of that?

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 10:21 am
by matthijs
of course
Code: Select all
public function get($key) {
return $this->has($key) ? $this->_store[$key] : null;
}
This better?
In bed with your Macbook? Take care you don't make your partner jealous (if you have one)

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 1:12 pm
by John Cartwright
Chris Corbyn wrote:
Not gone to bed yet

That's a lie. I'm in bed on my Macbook
Naughty Chris

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 2:32 pm
by Christopher
Jcart wrote:Chris Corbyn wrote:
Not gone to bed yet

That's a lie. I'm in bed on my Macbook
Naughty Chris

Chris + a Sheila + bed == Naughty
Chris + a MacBook + bed == Nice
Chris + a Sheila + a MacBook + bed == Kinky!
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Fri Apr 25, 2008 10:09 pm
by Chris Corbyn
Moving on...
When we picked up the initial spec for this project, we were talking about tree-like data structures (i.e. YAML/XML). In that case, we might have values stored at a path like:
foo -> bar -> zip
Should we stop for a moment to think about the interface for accessing that value with the key "zip" on branches "foo" then "bar"? Am I making any sense?

Basically if it were a PHP array it'd be:
Code: Select all
array (
'foo '=> array(
'bar' => array(
'zip' => 'some value'
)
)
);
What might a simple interface for querying that value be? Something like this maybe?
?
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 12:39 am
by matthijs
Good morning again
I think your interface looks good. What are alternatives?
Code: Select all
$dataStore->get('foo','bar','zip');
Your interface wih the slashes looks nicer and more familiar because it's also used for folders and URLs.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 12:45 am
by Chris Corbyn
matthijs wrote:What are alternatives?
Well, there are ways to do it using a namespace/hierarchy separator like a slash or a dot. But then we may have other ideas like this?
Code: Select all
$dataStore->get('foo')->get('bar')->get('zip');
I think that just adds unnecessary complexity, but just exploring the ideas
I do agree that just using slashes is a lot easier to read (and probably to use). Should we go with the slashes?

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 12:49 am
by matthijs
At first sight I would say let's go with the slashes. My only concern is: we want to support different kinds of data in the end. How does using slashes cope with that? Thinking about XML, CVS, etc.
Most data will be a bit more verbose then foo, bar and baz.
I'm just waking up so my brains not that fast yet

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 1:03 am
by Chris Corbyn
matthijs wrote:At first sight I would say let's go with the slashes. My only concern is: we want to support different kinds of data in the end. How does using slashes cope with that? Thinking about XML, CVS, etc.
We're only interested in storing key-value pairs with some nesting support. We don't have to implement the entire XML API. If at some point down the line we decide to support XPath-like queries then it'll probably degrade nicely to other formats anyway

For now, let's just concern ourselves with the most simple situations.
I don't think CSV was ever going to work well with this project since it's tabular and not tree-like. I'm sure there'd be a way to force it work but it would be messy

We'll move onto XmlModel when we finish this wrapper. It doesn't seem we're far away from being able to do that
I should probably discuss our options for writing the test for branching. First and foremost we want to know that values can get has(), set(), get() and remove()'d using the new syntax. But we also will need to ensure that the array we pass to $storageModel->save() is in a format we will stick to.
Let's do the tests for get(), set(), has() and remove() using our new syntax first. Hopefully we'll find that they "just work"

But we're about to see how the tests support our ability to refactor.
Care to write those get(), set(), has() and remove() tests?

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 1:24 am
by matthijs
Ok I'll give it a try!
Might take a moment, because I found out I've got to upgrade 15 wordpress sites (again

If these guys would have learned coding first on this forum I wouldn't have to do that every week)
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 8:22 am
by matthijs
Code: Select all
public function testGetDeeperNestedKeyReturnsRightValue(){
$storageModel = $this->_createStorageModel();
$storageModel->setReturnValue('load', array('foo' => array('bar'=>array('zip'=>'some value'))));
$dataStore = $this->_createDataStore($storageModel);
$this->assertEqual('some value',$dataStore->get('foo/bar/zip'));
}
public function testSetDeeperNestedValue(){
$this->_dataStore->set('foo/bar/zip', 'some value');
$this->assertEqual('some value', $this->_dataStore->get('foo/bar/zip'));
}
public function testHasDeeperNestedValue(){
$this->_dataStore->set('foo/bar/zip', 'some value');
$this->assertTrue($this->_dataStore->has('foo/bar/zip'));
}
That first test fails, the other two pass. But that's logical, as I'm not really testing a nested array there.. so the tests could be wrong.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 8:26 am
by Chris Corbyn
Interesting that you posted a version using load() rather than a straight set() followed by get() like we did initially

But that's ok anyway since that was what I was about to move onto.
So I guess we're both in agreement that the data structure which comes out of, and goes into load() and save() will just be a multidimensional array?

I'm happy with that and it's basically what I was thinking.
So can we get all our tests to pass with this setup if we modify our current design slightly?
EDIT | We're missing remove() too actually. Should probably add some test coverage for that one too

Re: TDD workshop. Anybody welcome; Data storage abstraction.
Posted: Sat Apr 26, 2008 9:00 am
by Chris Corbyn
I'm working on this now and I'll admit it's not as simple an algorithm as it would first seem. I have it cracked so if you're stuck I'll post my solution
