本文整理匯總了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']);
});
}