当前位置: 首页>>代码示例>>PHP>>正文


PHP Input::clearResolvedInstances方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Input::clearResolvedInstances方法的典型用法代码示例。如果您正苦于以下问题:PHP Input::clearResolvedInstances方法的具体用法?PHP Input::clearResolvedInstances怎么用?PHP Input::clearResolvedInstances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Input的用法示例。


在下文中一共展示了Input::clearResolvedInstances方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCriteria

 public function testCriteria()
 {
     $this->specify("sort criterion is applied when only one is given", function () {
         $this->assertCount(1, (array) TestModelWithSortableMethod::sorted(['sort' => 'field1,asc'])->getQuery()->orders);
     });
     $this->specify("sort criteria are applied when array is given", function () {
         $this->assertCount(2, (array) TestModelWithSortableMethod::sorted(['field1,asc', 'field2,desc'])->getQuery()->orders);
     });
     $this->specify("sort criterion is applied when only one is given", function () {
         $this->assertCount(1, (array) TestModelWithSortableMethod::sorted(['sort' => 'field1,asc'])->getQuery()->orders);
     });
     $this->specify("sort criteria are applied when array is given", function () {
         $this->assertCount(2, (array) TestModelWithSortableMethod::sorted(['field1,asc', 'field2,desc'])->getQuery()->orders);
     });
     $this->specify("criteria are applied only to sortable parameters", function () {
         $this->assertCount(0, (array) TestModelWithSortableMethod::sorted('field0,asc')->getQuery()->orders);
         $this->assertCount(1, (array) TestModelWithSortableMethod::sorted(['field0,asc', 'field1,desc'])->getQuery()->orders);
         $this->assertCount(2, (array) TestModelWithSortableMethod::sorted(['sort' => ['field0,asc', 'field1,desc', 'field2,desc']])->getQuery()->orders);
         $this->assertCount(2, (array) TestModelWithSortableMethod::sorted(['field0,asc', 'field1,desc', 'field2,desc', 'field3,desc'])->getQuery()->orders);
     });
     $this->specify("criteria are applied to columns by name", function () {
         $criterion = (array) TestModelWithSortableMethod::sorted('field1,asc')->getQuery()->orders[0];
         $this->assertEquals('field1', $criterion['column']);
     });
     $this->specify("criteria are applied in the same order as specified", function () {
         $criteria = (array) TestModelWithSortableMethod::sorted(['field1,desc', 'field2,desc'])->getQuery()->orders;
         $this->assertEquals('field1', $criteria[0]['column']);
         $this->assertEquals('field2', $criteria[1]['column']);
         $criteria = (array) TestModelWithSortableMethod::sorted(['field2,desc', 'field1,desc'])->getQuery()->orders;
         $this->assertEquals('field2', $criteria[0]['column']);
         $this->assertEquals('field1', $criteria[1]['column']);
     });
     $this->specify('getSearchableAttribues is not required, if $searchable property exists', function () {
         $criteria = (array) TestModelWithSortableProperty::sorted(['field2,desc', 'field1,desc'])->getQuery()->orders;
         $this->assertEquals('field2', $criteria[0]['column']);
         $this->assertEquals('field1', $criteria[1]['column']);
     });
     $this->specify('model must implement getSortableAttributes() or have $sortable property', function () {
         TestModel::sorted(['field1,desc', 'field2,desc']);
     }, ['throws' => new RuntimeException()]);
     $this->specify('* in searchable field list makes all fields searchable', function () {
         $criteria = (array) TestModelWithAllFieldsSortable::sorted(['field2,desc', 'field42,desc'])->getQuery()->orders;
         $this->assertEquals('field2', $criteria[0]['column']);
         $this->assertEquals('field42', $criteria[1]['column']);
     });
     $this->specify('available callback method is used in lieu of standard sorting', function () {
         $criteria = (array) TestModelWithSortableCallbackMethod::sorted(['created_at,desc'])->getQuery()->orders;
         $this->assertEquals('created', $criteria[0]['column']);
         $this->assertEquals('desc', $criteria[0]['direction']);
     });
     $this->specify('default sorting criteria are applied', function () {
         Input::clearResolvedInstances();
         Input::shouldReceive('input')->andReturn(null);
         $criteria = (array) TestModelWithDefaultSortingCriteria::sorted()->getQuery()->orders;
         $this->assertEquals('column1', $criteria[0]['column']);
         $this->assertEquals('desc', $criteria[0]['direction']);
         $this->assertEquals('column2', $criteria[1]['column']);
         $this->assertEquals('asc', $criteria[1]['direction']);
     });
     $this->specify('default sorting order is applied', function () {
         Input::clearResolvedInstances();
         Input::shouldReceive('input')->andReturn(['sort' => 'column1']);
         $criteria = (array) TestModelWithDefaultSortOrder::sorted()->getQuery()->orders;
         $this->assertEquals('column1', $criteria[0]['column']);
         $this->assertEquals('desc', $criteria[0]['direction']);
         Input::clearResolvedInstances();
         Input::shouldReceive('input')->andReturn(['sort' => 'column1']);
         $criteria = (array) TestModelWithAllFieldsSortable::sorted()->getQuery()->orders;
         $this->assertEquals('column1', $criteria[0]['column']);
         $this->assertEquals('asc', $criteria[0]['direction']);
     });
 }
开发者ID:jedrzej,项目名称:sortable,代码行数:72,代码来源:SortableTraitTest.php


注:本文中的Illuminate\Support\Facades\Input::clearResolvedInstances方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。