There's no foo/bar2/zip2 in your codearjan.top wrote:chris I think your code is not ok
For example if you have this array:... and you want foo/bar2/zip2Code: Select all
array( 'foo' => array( 'bar' => array( 'zip' => 'some value' ) ), 'bar2' => array( 'zip2' => 'some other value' ) )
TDD workshop. Anybody welcome; Data storage abstraction.
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
hey, but in your test you ask for
, while in the other test it is
If you try
you get a failing test.
[edit]To prevent confusion, I mean;
Code: Select all
$dataStore->get('bar2/zip2')Code: Select all
$dataStore->get('foo/bar/zip')Code: Select all
$dataStore->get('foo/bar2/zip2')[edit]To prevent confusion, I mean;
Code: Select all
public function testGettingValueOnSecondPrimaryBranch() {
$storageModel = $this->_createStorageModel();
$storageModel->setReturnValue('load', array(
'foo' => array(
'bar' => array(
'zip' => 'some value'
)
),
'bar2' => array(
'zip2' => 'some other value'
)
));
$dataStore = $this->_createDataStore($storageModel);
$this->assertEqual('some other value', $dataStore->get('foo/bar2/zip2'));
}- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Of course I do. It should fail. Where is foo/bar2/zip2 in that array?

The only paths in that array are foo/bar/zip AND bar2/zip2.
The only paths in that array are foo/bar/zip AND bar2/zip2.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Code: Select all
$this->assertEqual('some other value', $dataStore->get('bar2/zip2'));
EDIT:
oops new page already, missed some posts ...
Last edited by arjan.top on Sun Apr 27, 2008 4:56 am, edited 1 time in total.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Just look at it in it's array form. To get foo/bar2/zip2 we'd need:
The test is incorrect 
EDIT | Please see my first post on Page 9 of this discussion
Code: Select all
array(
'foo' => array(
'bar2' => array(
'zip2' => 'something'
)
),
'bar' => array(
'zip' => 'some value'
)
)
),
'bar2' => array(
'zip2' => 'some other value'
)
);EDIT | Please see my first post on Page 9 of this discussion
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Yes I see, I made I mistake 
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Arggh, I saw that too just now
Somehow it's very difficult to count and match brackets...
Somehow it's very difficult to count and match brackets...
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
That's fine. We need to keep thinking of things which aren't right and then adding a test to prove it. Just happens in this case that the thing you though wasn't right was a result of a little confusionarjan.top wrote:Yes I see, I made I mistake
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Exactly the reason I always write multidimensional array as indented nestsmatthijs wrote:Arggh, I saw that too just now![]()
Somehow it's very difficult to count and match brackets...
Look at the veritcal alignment of 'foo' in the array, then look directly down from it; you hit 'bar2', so that mean it's in the same dimension
Re: TDD workshop. Anybody welcome; Data storage abstraction.
I just looked at how brackets are aligned and I added array in the wrong placematthijs wrote:Arggh, I saw that too just now![]()
Somehow it's very difficult to count and match brackets...
Re: TDD workshop. Anybody welcome; Data storage abstraction.
So, if everybody's got his or her brackets aligned again, what's next? 
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Ok, all together now!

Ok, time to continue....
Ok, time to continue....
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Right. Sit down and stop talking class!
How's about we make sure that the array we're passing to save() is what we want to pass? So far we haven't validated what is passed to it. This is a new one for you probably matthijs since it's an extra parameter on $storageModel->expectOnce('save', ...).
Just two tests will do. One for a single value in a one dimensional array, then one for our more complex multidimensional array.
How's about we make sure that the array we're passing to save() is what we want to pass? So far we haven't validated what is passed to it. This is a new one for you probably matthijs since it's an extra parameter on $storageModel->expectOnce('save', ...).
Just two tests will do. One for a single value in a one dimensional array, then one for our more complex multidimensional array.
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Maybe you have to explain a bit more about what you expect save to do. I don't entirely understand it. Isn't the storageModel supposed to validate the data?
It's probably simple, but maybe my idea of how the classes work doesn't match up with yours.
It's probably simple, but maybe my idea of how the classes work doesn't match up with yours.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: TDD workshop. Anybody welcome; Data storage abstraction.
Definitely worth further explanation. We all need to be clear what we're doing. In my opinion, save() should accept an array in exactly the same format as the array provided by load(). When that array is modified (by set() or remove()) the array passed to save() should reflect that modification.matthijs wrote:Maybe you have to explain a bit more about what you expect save to do. I don't entirely understand it. Isn't the storageModel supposed to validate the data?
It's probably simple, but maybe my idea of how the classes work doesn't match up with yours.
We don't care what happens to the internal array ($this->_store) when set() or remove() are called. We don't even care that such an internal array exists. What we do care about is that save() receives integral data.
I can write a really simple first test if you like? Really simple!
Code: Select all
public function testSavingSingleValuePassesSimpleArray() {
$storageModel = $this->_createStorageModel();
$storageModel->expectOnce('save', array( array('zip' => 'button') ));
$dataStore = $this->_createDataStore($storageModel);
$dataStore->set('zip', 'button');
$dataStore->save();
}