-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#111. Add more coverage on JwtTrait/FsmTrait
- Loading branch information
1 parent
69167be
commit 2e75bba
Showing
8 changed files
with
193 additions
and
8 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,38 @@ | ||
<?php | ||
|
||
namespace rjapitest\_data; | ||
|
||
|
||
use Modules\V2\Entities\Article; | ||
|
||
class ArticleFixture | ||
{ | ||
/** | ||
* @return Article | ||
*/ | ||
public static function createAndGet() : Article | ||
{ | ||
$article = new Article(); | ||
$article->id = '124ea1e595ed11225727e7730d653669'; | ||
$article->title = 'Foo bar Foo bar Foo bar Foo bar'; | ||
$article->description = 'The quick brovn fox jumped ower the lazy dogg'; | ||
$article->url = 'http://example.com/articles_feed_123'; | ||
$article->topic_id = 1; | ||
$article->rate = 5.0; | ||
$article->status = 'draft'; | ||
$article->show_in_top = 1; | ||
$article->date_posted = date('Y-m-d'); | ||
$article->time_to_live = date('H:i:s'); | ||
$article->save(); | ||
|
||
return $article; | ||
} | ||
|
||
/** | ||
* @param $id | ||
*/ | ||
public static function delete($id) : void | ||
{ | ||
Article::where('id', $id)->first(['*'])->delete(); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
namespace rjapitest\_data; | ||
|
||
use Modules\V2\Entities\User; | ||
|
||
class UserFixture | ||
{ | ||
/** | ||
* @return User | ||
*/ | ||
public static function createAndGet() : User | ||
{ | ||
$user = new User(); | ||
$user->first_name = 'Linus'; | ||
$user->last_name = 'Gates'; | ||
$user->password = 'secret'; | ||
$user->jwt = 'jwt'; | ||
$user->permissions = 2; | ||
$user->save(); | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @param $id | ||
*/ | ||
public static function delete($id) : void | ||
{ | ||
User::where('id', $id)->first(['*'])->delete(); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
|
||
namespace rjapitest\unit\extensions; | ||
|
||
use rjapi\extension\BaseModel; | ||
use rjapi\extension\JWTTrait; | ||
use rjapi\types\ModelsInterface; | ||
use rjapitest\_data\UserFixture; | ||
use rjapitest\unit\TestCase; | ||
|
||
class User extends BaseModel | ||
{ | ||
// >>>props>>> | ||
protected $primaryKey = 'id'; | ||
protected $table = 'user'; | ||
public $timestamps = false; | ||
// <<<props<<< | ||
// >>>methods>>> | ||
|
||
// <<<methods<<< | ||
} | ||
|
||
class JwtTraitTest extends TestCase | ||
{ | ||
use JWTTrait; | ||
|
||
private $model; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
$this->model = new User(); | ||
$this->model->id = 1; | ||
$this->model->password = 'secret'; | ||
$_SERVER['HTTP_HOST'] = 'example.com'; | ||
} | ||
|
||
/** | ||
* @uses getEntity | ||
* @test | ||
*/ | ||
public function it_creates_jwt_user() | ||
{ | ||
$this->createJwtUser(); | ||
$this->assertEmpty($this->model->password); | ||
// 2nd call with empty password to emulate error | ||
$this->createJwtUser(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_updates_jwt_user() | ||
{ | ||
$user = $this->getEntity(1); // fake id | ||
$this->assertInstanceOf(BaseModel::class, $user); | ||
$this->updateJwtUser($user, ['password' => 'secret']); | ||
UserFixture::delete($user->id); | ||
} | ||
|
||
/** | ||
* Params needed for internal calls | ||
* @param $id | ||
* @param array $data | ||
* @return \Modules\V2\Entities\User | ||
*/ | ||
private function getEntity($id, array $data = ModelsInterface::DEFAULT_DATA) | ||
{ | ||
return UserFixture::createAndGet(); | ||
} | ||
} |
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