public function testShouldUpdateRecordsAccordingToCriteria() { $record1 = new Record(array('name' => 'A')); $record2 = new Record(array('name' => 'A')); $collection = new Collection(new Factory()); $collection->insert($record1); $collection->insert($record2); $update = array('name' => 'C'); $criteria = array('name' => 'D'); $result = $collection->update($update, $criteria); $expectedTrue = true; foreach ($collection as $record) { $expectedTrue = $expectedTrue && $record->name == 'A'; } $this->assertTrue($expectedTrue); }
/** * Validates All fields in _updates queue * * @param bool $includeAllRules - Will also run rules not validated * * @return bool */ protected function validateAll($includeAllRules = false) { if ($includeAllRules) { /* * Include fields that might not have been included */ $fieldData = new Collection(array_fill_keys(array_keys($this->_validations->toArray()), null)); $fieldData->update($this->_updates->toArray()); } else { $fieldData = clone $this->_updates; } foreach ($fieldData->toArray() as $field => $val) { //Match double fields $field2 = $field . '2'; if (!is_null($fieldData->{$field2})) { // Compared the two double fields if ($val != $fieldData->{$field2}) { $this->log->formError($field, ucfirst($field) . 's did not match'); } else { $this->log->report(ucfirst($field) . 's matched'); } } // Trim white spaces at end and start if ($this->_updates->{$field}) { $this->_updates->{$field} = trim($val); } // Check if a validation rule exists for the field if ($validation = $this->_validations->{$field}) { $this->validate($field, $validation->limit, $validation->regEx); } } return !$this->log->hasError(); }
Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('POST /v1/main/collection', function () { try { $object = Collection::insert(); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('PUT /v1/main/collection/@id', function ($id) { try { $object = Collection::update($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('DELETE /v1/main/collection/@id', function ($id) { try { $object = Collection::delete($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); //============================================================================= //Company