Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master with failing tests #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tests/Feature/HasRelationshipObservablesTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Chelout\RelationshipEvents\Tests\Feature;

use Chelout\RelationshipEvents\Tests\Stubs\Role;
use Chelout\RelationshipEvents\Tests\Stubs\User;
use Chelout\RelationshipEvents\Tests\TestCase;

class HasRelationshipObservablesTraitTest extends TestCase
{
public function setup(): void
{
parent::setup();

User::setupTable();
Role::setupTable();
}

/** @test */
public function it_fails_first_time()
{
$user = User::create();
$role = Role::create(['name' => 'admin']);
$user->roles()->attach($role);


$this->assertEquals(
collect(User::getRelationshipObservables())->count(),
collect(User::getRelationshipObservables())->unique()->count()
);
}

/** @test */
public function it_fails_even_greater_second_time()
{
$this->withoutJobs();
$this->beforeApplicationDestroyed(function () {
$this->assertCount(1, $this->dispatchedJobs);
});

$user = User::create();
$role = Role::create(['name' => 'admin']);
$user->roles()->attach($role);

$this->assertEquals(
collect(User::getRelationshipObservables())->count(),
collect(User::getRelationshipObservables())->unique()->count()
);

}
}
20 changes: 20 additions & 0 deletions tests/Stubs/Jobs/TestJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Chelout\RelationshipEvents\Tests\Stubs\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class TestJob implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct() {

}

public function handle() {

}
}
11 changes: 11 additions & 0 deletions tests/Stubs/Observers/UserObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Chelout\RelationshipEvents\Tests\Stubs\Observers;

use Chelout\RelationshipEvents\Tests\Stubs\Jobs\TestJob;

class UserObserver {
public function belongsToManyAttached($relation, $user, $ids) {
TestJob::dispatch();
}
}
11 changes: 9 additions & 2 deletions tests/Stubs/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Chelout\RelationshipEvents\Concerns\HasManyEvents;
use Chelout\RelationshipEvents\Concerns\HasMorphOneEvents;
use Chelout\RelationshipEvents\Concerns\HasOneEvents;
use Chelout\RelationshipEvents\Tests\Stubs\Observers\UserObserver;
use Chelout\RelationshipEvents\Traits\HasRelationshipObservables;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -15,9 +17,14 @@ class User extends Model
use HasOneEvents;
use HasManyEvents;
use HasMorphOneEvents;
use HasBelongsToManyEvents;
use HasBelongsToManyEvents;
use HasRelationshipObservables;
protected static function boot() {
parent::boot(); // TODO: Change the autogenerated stub
self::observe(UserObserver::class);
}

public static function setupTable()
public static function setupTable()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
Expand Down