-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add has(), isArray() and isScalar() methods
- Loading branch information
Showing
4 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
use Crwlr\QueryString\Query; | ||
|
||
it('returns false when it does not have a certain key', function () { | ||
expect(Query::fromArray(['foo' => 'a', 'bar' => 'b'])->has('baz'))->toBeFalse(); | ||
}); | ||
|
||
it('returns true when it has a certain key', function () { | ||
expect(Query::fromArray(['foo' => 'a', 'bar' => 'b'])->has('bar'))->toBeTrue(); | ||
}); | ||
|
||
it('returns true when it does not have a certain numeric index key', function () { | ||
expect(Query::fromArray(['foo', 'bar'])->has(2))->toBeFalse(); | ||
}); | ||
|
||
it('returns false when it has a certain numeric index key', function () { | ||
expect(Query::fromArray(['foo', 'bar'])->has(1))->toBeTrue(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use Crwlr\QueryString\Query; | ||
|
||
test('isArray returns false when key is not an array', function ($value) { | ||
expect(Query::fromArray(['foo' => $value])->isArray('foo'))->toBeFalse(); | ||
})->with([ | ||
'string', | ||
true, | ||
false, | ||
1, | ||
1.234, | ||
]); | ||
|
||
test('isArray returns false when key does not exist', function () { | ||
expect(Query::fromArray(['foo' => ['test']])->isArray('bar'))->toBeFalse(); | ||
}); | ||
|
||
test('isArray returns true when key is an array', function () { | ||
expect(Query::fromArray(['foo' => ['test']])->isArray('foo'))->toBeTrue(); | ||
}); | ||
|
||
test('isScalar returns false when key is an array', function () { | ||
expect(Query::fromArray(['foo' => ['test']])->isScalar('foo'))->toBeFalse(); | ||
}); | ||
|
||
test('isScalar returns false when key is an instance of Query', function () { | ||
$query = Query::fromArray(['foo' => ['test']]); | ||
|
||
$query->get('foo'); | ||
|
||
expect($query->isScalar('foo'))->toBeFalse(); | ||
}); | ||
|
||
test('isScalar returns false when key does not exist', function () { | ||
expect(Query::fromArray(['foo' => 'test'])->isScalar('bar'))->toBeFalse(); | ||
}); | ||
|
||
test('isScalar returns true when key has a scalar value', function ($value) { | ||
expect(Query::fromArray(['foo' => $value])->isScalar('foo'))->toBeTrue(); | ||
})->with([ | ||
'string', | ||
true, | ||
false, | ||
1, | ||
1.234, | ||
]); |