Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d23e39a

Browse files
Added unit tests
1 parent 03ed568 commit d23e39a

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

‎app/User.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,13 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
3131
*/
3232
protected $hidden = ['password', 'remember_token'];
3333

34+
/**
35+
* @param array $data
36+
* @return User
37+
*/
38+
public static function register($data = [])
39+
{
40+
return static::create($data);
41+
}
42+
3443
}

‎tests/_support/Helper/Unit.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
namespace Helper;
3+
// here you can define custom actions
4+
// all public methods declared in helper class will be available in $I
5+
6+
class Unit extends \Codeception\Module
7+
{
8+
9+
}

‎tests/_support/UnitTester.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class UnitTester extends \Codeception\Actor
20+
{
21+
use _generated\UnitTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}

‎tests/unit.suite.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class_name: UnitTester
2+
modules:
3+
enabled:
4+
- \Helper\Unit
5+
- Laravel5:
6+
environment_file: .env.testing

‎tests/unit/UserTest.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
4+
use App\User;
5+
use Illuminate\Support\Facades\Hash;
6+
7+
class UserTest extends \Codeception\TestCase\Test
8+
{
9+
/**
10+
* @var \UnitTester
11+
*/
12+
protected $tester;
13+
14+
public function testRegister()
15+
{
16+
$email = 'johndoe@example.com';
17+
$password = Hash::make('password');
18+
19+
User::register(['email' => $email, 'password' => $password]);
20+
21+
$this->tester->seeRecord('users', ['email' => $email, 'password' => $password]);
22+
}
23+
24+
}

‎tests/unit/_bootstrap.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
// Here you can initialize variables that will be available to your tests

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /