/** * @test */ public function it_returns_the_array_of_operators() { $operators = ['!=' => 'NotEquals', '<=' => 'LessThanEquals', '>=' => 'GreaterThanEquals', '=' => 'Equals', '<' => 'LessThan', '>' => 'GreaterThan', 'contains' => 'Contains', 'like' => 'Like']; foreach ($operators as $operator => $description) { $this->assertArraySubset([$operator => $description], $this->filter->getOperators()); } $this->assertEquals(count($operators), count($this->filter->getOperators())); }
/** * Determines the parameters and calls Where with a property in the method name * * @param array $arguments * @param array &$parts * * @return $this * @throws InvalidArgumentException */ private function runWhereWithPropertyMethod(array $arguments, array &$parts) { if (count($arguments) !== 1) { throw new InvalidArgumentException("You must pass a value for the property to filter the results."); } $parts = array_pad($parts, 3, null); $property = $parts[2]; $value = $arguments[0]; $logical = $parts[1]; foreach ($this->filter->getOperators() as $operator => $description) { if (ends_with($property, $description)) { // Remove description off of the end of the property $property = str_replace($description, '', $property); $this->filter = $this->filter->where($property, $value, $operator, $logical); return $this; } } // Default to equals $this->filter = $this->filter->where($property, $value, '=', $logical); return $this; }