diff options
Diffstat (limited to 'main/app/sprinkles/core/tests/Unit')
3 files changed, 26 insertions, 37 deletions
diff --git a/main/app/sprinkles/core/tests/Unit/BelongsToManyThroughTest.php b/main/app/sprinkles/core/tests/Unit/BelongsToManyThroughTest.php index d4fd4f8..04d3843 100644 --- a/main/app/sprinkles/core/tests/Unit/BelongsToManyThroughTest.php +++ b/main/app/sprinkles/core/tests/Unit/BelongsToManyThroughTest.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Tests\Unit; use Illuminate\Database\Capsule\Manager as DB; @@ -25,13 +26,11 @@ use UserFrosting\Sprinkle\Core\Database\Relations\BelongsToManyThrough; */ class BelongsToManyThroughTest extends TestCase { - public function tearDown() - { + public function tearDown() { m::close(); } - function testPaginatedQuery() - { + function testPaginatedQuery() { // Creates a real BelongsToManyThrough object $relation = $this->getRelation(); @@ -51,11 +50,11 @@ class BelongsToManyThroughTest extends TestCase // Mock the collection generated by the constrained query $collection = m::mock('Illuminate\Database\Eloquent\Collection'); $collection->shouldReceive('pluck')->once()->with('id')->andReturn($collection); - $collection->shouldReceive('toArray')->once()->andReturn([1,2]); + $collection->shouldReceive('toArray')->once()->andReturn([1, 2]); $builder->shouldReceive('get')->once()->andReturn($collection); // Test the final modification to the original unpaginated query - $builder->shouldReceive('whereIn')->once()->with('users.id', [1,2])->andReturnSelf(); + $builder->shouldReceive('whereIn')->once()->with('users.id', [1, 2])->andReturnSelf(); $paginatedQuery = $relation->getPaginatedQuery($builder, 2, 1); } @@ -63,8 +62,7 @@ class BelongsToManyThroughTest extends TestCase /** * Set up and simulate base expectations for arguments to relationship. */ - protected function getRelation() - { + protected function getRelation() { // We simulate a BelongsToManyThrough relationship that gets all related users for a specified permission(s). $builder = m::mock(EloquentBuilder::class); $related = m::mock('Illuminate\Database\Eloquent\Model'); diff --git a/main/app/sprinkles/core/tests/Unit/DatabaseSyncableTest.php b/main/app/sprinkles/core/tests/Unit/DatabaseSyncableTest.php index 188b012..d53976a 100644 --- a/main/app/sprinkles/core/tests/Unit/DatabaseSyncableTest.php +++ b/main/app/sprinkles/core/tests/Unit/DatabaseSyncableTest.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Tests\Unit; use stdClass; @@ -20,16 +21,14 @@ use UserFrosting\Sprinkle\Core\Database\Relations\HasManySyncable; class DatabaseSyncableTest extends TestCase { - public function tearDown() - { + public function tearDown() { m::close(); } /** * @dataProvider syncMethodHasManyListProvider */ - public function testSyncMethod($list) - { + public function testSyncMethod($list) { $relation = $this->getRelation(); // Simulate determination of related key from builder @@ -58,15 +57,14 @@ class DatabaseSyncableTest extends TestCase 'id' => 'x' ]); $model->shouldReceive('getAttribute')->with('id')->andReturn('x'); - - $this->assertEquals(['created' => ['x'], 'deleted' => [1], 'updated' => [2,3]], $relation->sync($list)); + + $this->assertEquals(['created' => ['x'], 'deleted' => [1], 'updated' => [2, 3]], $relation->sync($list)); } /** * Set up and simulate base expectations for arguments to relationship. */ - protected function getRelation() - { + protected function getRelation() { $builder = m::mock('Illuminate\Database\Eloquent\Builder'); $builder->shouldReceive('whereNotNull')->with('table.foreign_key'); $builder->shouldReceive('where')->with('table.foreign_key', '=', 1); @@ -79,8 +77,7 @@ class DatabaseSyncableTest extends TestCase return new HasManySyncable($builder, $parent, 'table.foreign_key', 'id'); } - public function syncMethodHasManyListProvider() - { + public function syncMethodHasManyListProvider() { return [ // First test set [ @@ -103,15 +100,13 @@ class DatabaseSyncableTest extends TestCase ]; } - protected function expectNewModel($relation, $attributes = null) - { + protected function expectNewModel($relation, $attributes = NULL) { $relation->getRelated()->shouldReceive('newInstance')->once()->with($attributes)->andReturn($model = m::mock(Model::class)); $model->shouldReceive('setAttribute')->with('foreign_key', 1)->andReturn($model); return $model; } - protected function expectCreatedModel($relation, $attributes) - { + protected function expectCreatedModel($relation, $attributes) { $model = $this->expectNewModel($relation, $attributes); $model->shouldReceive('save')->andReturn($model); return $model; diff --git a/main/app/sprinkles/core/tests/Unit/SprunjeTest.php b/main/app/sprinkles/core/tests/Unit/SprunjeTest.php index fa19319..dab34a5 100644 --- a/main/app/sprinkles/core/tests/Unit/SprunjeTest.php +++ b/main/app/sprinkles/core/tests/Unit/SprunjeTest.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\Tests\Unit; use Illuminate\Database\Capsule\Manager as DB; @@ -24,13 +25,11 @@ use UserFrosting\Sprinkle\Core\Util\ClassMapper; */ class SprunjeTest extends TestCase { - public function tearDown() - { + public function tearDown() { m::close(); } - function testSprunjeApplyFiltersDefault() - { + function testSprunjeApplyFiltersDefault() { $sprunje = new SprunjeStub([ 'filters' => [ 'species' => 'Tyto' @@ -42,17 +41,16 @@ class SprunjeTest extends TestCase // Need to mock the new Builder instance that Laravel spawns in the where() closure. // See https://stackoverflow.com/questions/20701679/mocking-callbacks-in-laravel-4-mockery $builder->shouldReceive('newQuery')->andReturn( - $subBuilder = m::mock(Builder::class, function ($subQuery) { - $subQuery->makePartial(); - $subQuery->shouldReceive('orLike')->with('species', 'Tyto')->once()->andReturn($subQuery); - }) - ); + $subBuilder = m::mock(Builder::class, function ($subQuery) { + $subQuery->makePartial(); + $subQuery->shouldReceive('orLike')->with('species', 'Tyto')->once()->andReturn($subQuery); + }) + ); $sprunje->applyFilters($builder); } - function testSprunjeApplySortsDefault() - { + function testSprunjeApplySortsDefault() { $sprunje = new SprunjeStub([ 'sorts' => [ 'species' => 'asc' @@ -76,14 +74,12 @@ class SprunjeStub extends Sprunje 'species' ]; - public function __construct($options) - { + public function __construct($options) { $classMapper = new ClassMapper(); parent::__construct($classMapper, $options); } - protected function baseQuery() - { + protected function baseQuery() { // We use a partial mock for Builder, because we need to be able to run some of its actual methods. // For example, we need to be able to run the `where` method with a closure. $builder = m::mock(Builder::class); |