Skip to content

Commit

Permalink
Merge pull request #3 from tattersoftware/test
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Feb 21, 2021
2 parents 370c464 + ecc1624 commit d28122e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
33 changes: 32 additions & 1 deletion tests/_support/FactoryTestCase.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php namespace Tests\Support;

use Tatter\Users\UserEntity;
use Tatter\Users\UserFactory;

class FactoryTestCase extends DatabaseTestCase
abstract class FactoryTestCase extends DatabaseTestCase
{
/**
* The factory class to test.
Expand Down Expand Up @@ -42,4 +43,34 @@ protected function setUp(): void
$this->user = fake($this->faker);
$this->factory = new $this->class();
}

public function testId()
{
$result = $this->factory->findById($this->user->id);

$this->assertInstanceof(UserEntity::class, $result);
$this->assertEquals($this->user->id, $result->getId());
}

public function testEmail()
{
// Shield's faker does not include email yet
if ($this->faker === 'Sparks\Shield\Models\UserModel')
{
$this->markTestSkipped();
}

$result = $this->factory->findByEmail($this->user->email);

$this->assertInstanceof(UserEntity::class, $result);
$this->assertEquals($this->user->id, $result->getId());
}

public function testUsername()
{
$result = $this->factory->findByUsername($this->user->username);

$this->assertInstanceof(UserEntity::class, $result);
$this->assertEquals($this->user->id, $result->getId());
}
}
9 changes: 0 additions & 9 deletions tests/unit/MythFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

use Myth\Auth\Test\Fakers\UserFaker;
use Tatter\Users\Factories\MythFactory;
use Tatter\Users\UserEntity;
use Tests\Support\FactoryTestCase;

class MythFactoryTest extends FactoryTestCase
{
protected $namespace = 'Myth\Auth';
protected $class = MythFactory::class;
protected $faker = UserFaker::class;

public function testId()
{
$result = $this->factory->findById($this->user->id);

$this->assertInstanceof(UserEntity::class, $result);
$this->assertEquals($this->user->username, $result->getUsername());
}
}
9 changes: 0 additions & 9 deletions tests/unit/ShieldFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@

use Sparks\Shield\Models\UserModel;
use Tatter\Users\Factories\ShieldFactory;
use Tatter\Users\UserEntity;
use Tests\Support\FactoryTestCase;

class ShieldFactoryTest extends FactoryTestCase
{
protected $namespace = 'Sparks\Shield';
protected $class = ShieldFactory::class;
protected $faker = UserModel::class;

public function testId()
{
$result = $this->factory->findById($this->user->id);

$this->assertInstanceof(UserEntity::class, $result);
$this->assertEquals($this->user->username, $result->getUsername());
}
}

0 comments on commit d28122e

Please sign in to comment.