コード例 #1
0
 /**
  * @test
  */
 public function shouldValidateSortingParameters()
 {
     $violation = $this->getMockBuilder(ConstraintViolationBuilderInterface::class)->getMock();
     $violation->expects($this->once())->method('setParameters')->with(['%fields%' => "'store.name', 'name'"])->willReturnSelf();
     $violation->expects($this->once())->method('setPlural')->with(2)->willReturnSelf();
     $violation->expects($this->once())->method('setInvalidValue')->with(['store.name', 'name'])->willReturnSelf();
     $violation->expects($this->once())->method('setCode')->with(ListQueryParameters::INVALID_SORTING)->willReturnSelf();
     $violation->expects($this->once())->method('atPath')->with('sortParameters')->willReturnSelf();
     $violation->expects($this->once())->method('addViolation');
     $context = $this->getMockBuilder(ExecutionContextInterface::class)->getMock();
     $context->expects($this->once())->method('buildViolation')->with('Sorting by following fields is not supported: %fields%')->willReturn($violation);
     $query = new ListQueryParameters();
     $query->validateSortParameters($context);
     $query->setSortParameters($query->parseSortingParameters('-store.name,name'))->validateSortParameters($context);
 }