ardent
ardent copied to clipboard
Ardent breaks testing when passing arrays
I have a function which roughly looks like this:
Input::replace(array('name' => 'Test Product', 'options' => array(array('title' => 'Default'), array('title' => 'Colour'))));
$product = new Product;
$product->save();
I am saving the product, then using the afterSave
callback to save or update the options which have been passed. If my model extends Ardent I get the following error on tests:
ErrorException: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
./vendor/laravel/framework/src/Illuminate/Support/helpers.php:916
./vendor/laravel/framework/src/Illuminate/Database/QueryException.php:53
./vendor/laravel/framework/src/Illuminate/Database/QueryException.php:35
./vendor/laravel/framework/src/Illuminate/Database/Connection.php:539
./vendor/laravel/framework/src/Illuminate/Database/Connection.php:338
./vendor/laravel/framework/src/Illuminate/Database/Connection.php:295
./vendor/laravel/framework/src/Illuminate/Database/Query/Processors/Processor.php:30
./vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:1642
./vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:872
./vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1407
./vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1407
./vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1377
./vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1288
./vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:711
./vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:580
./vendor/laravelbook/ardent/src/LaravelBook/Ardent/Ardent.php:604
./app/tests/Admin/ProductTest.php:28
If the model extends Eloquent the test runs fine, however if I run the same code in my browser while the model is extending Ardent it creates the records and the options without complaining and returns no errors so the issue seems localised to tests.
Further to this, if I remove the validation rules from the model the error also goes away so it's localised to testing + validation rules.
I'm using these rules for validation:
public static $rules = array(
'cost' => array('numeric'),
'name' => array('required'),
'price' => array('numeric'),
);
The validation still occurs correctly when loading the code in the browser, e.g is name is missing an error is returned.