I have the following class
class Customer {}
and it has properties like Id, Name, City and Country and methods like findById and findByCity. I want to write a spec test that will test that my Customer::save() function works like this
function it_should_update_customer_name_on_save()
{
$customer = $this->findById(1);
$customer->Name = 'Compu-Global-Hyper-Mega-Net';
$customer->save();
$this->findById(1)->shouldReturn('Compu-Global-Hyper-Mega-Net');
}
but phpspec keeps throwing this error back at me
! it should update name on save (111ms)
error: Argument 1 passed to PHPSpec2\Wrapper\ArgumentsUnwrapper::unwrapAll() must be of the type array, string given,
called in /Users/kristiannissen/Documents/php/phpecosrv/vendor/phpspec/phpspec2/src/PHPSpec2/Prophet/ObjectProphet.php
on line 126 and defined in
/Users/kristiannissen/Documents/php/phpecosrv/vendor/phpspec/phpspec2/src/PHPSpec2/Wrapper/ArgumentsUnwrapper.php line
10
how should I perform this kind of test?
You are performing an integration test between your model and the database, that's not the goal of phpspec.
The saving responsability of the Customer should not be inside the customer Class anyway, it should be in a domain service.
findById
should be performed by a repository class, and save
by an entity manager class, inject both, and mock them.