Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Platform
Commits
81101e30
Commit
81101e30
authored
Sep 13, 2016
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding a test for the UserRegistration class
parent
018570f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
0 deletions
+111
-0
BaseUserTestCase.php
Modules/User/Tests/BaseUserTestCase.php
+59
-0
UserRegistrationTest.php
Modules/User/Tests/UserRegistrationTest.php
+52
-0
No files found.
Modules/User/Tests/BaseUserTestCase.php
0 → 100644
View file @
81101e30
<?php
namespace
Modules\User\Tests
;
use
Illuminate\View\ViewServiceProvider
;
use
Modules\Core\Providers\CoreServiceProvider
;
use
Modules\User\Providers\UserServiceProvider
;
use
Nwidart\Modules\LaravelModulesServiceProvider
;
use
Orchestra\Testbench\TestCase
;
abstract
class
BaseUserTestCase
extends
TestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
resetDatabase
();
}
protected
function
getPackageProviders
(
$app
)
{
return
[
ViewServiceProvider
::
class
,
LaravelModulesServiceProvider
::
class
,
CoreServiceProvider
::
class
,
UserServiceProvider
::
class
,
];
}
protected
function
getEnvironmentSetUp
(
$app
)
{
$app
[
'path.base'
]
=
__DIR__
.
'/..'
;
$app
[
'config'
]
->
set
(
'database.default'
,
'sqlite'
);
$app
[
'config'
]
->
set
(
'database.connections.sqlite'
,
array
(
'driver'
=>
'sqlite'
,
'database'
=>
':memory:'
,
'prefix'
=>
''
,
));
$app
[
'config'
]
->
set
(
'translatable.locales'
,
[
'en'
,
'fr'
]);
$app
[
'config'
]
->
set
(
'modules.paths.modules'
,
__DIR__
.
'/../Modules'
);
}
private
function
resetDatabase
()
{
// Makes sure the migrations table is created
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
]);
// We empty all tables
$this
->
artisan
(
'migrate:reset'
,
[
'--database'
=>
'sqlite'
,
]);
// Migrate
$this
->
artisan
(
'migrate'
,
[
'--database'
=>
'sqlite'
,
]);
$this
->
artisan
(
'migrate'
);
}
}
Modules/User/Tests/UserRegistrationTest.php
0 → 100644
View file @
81101e30
<?php
namespace
Modules\User\Tests
;
use
Illuminate\Foundation\Testing\DatabaseMigrations
;
use
Modules\User\Repositories\RoleRepository
;
use
Modules\User\Repositories\UserRepository
;
use
Modules\User\Services\UserRegistration
;
class
UserRegistrationTest
extends
BaseUserTestCase
{
/**
* @var RoleRepository
*/
private
$role
;
/**
* @var UserRepository
*/
private
$user
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
role
=
app
(
RoleRepository
::
class
);
$this
->
user
=
app
(
UserRepository
::
class
);
}
/** @test */
public
function
it_registers_a_new_user_with_user_role
()
{
$this
->
createRole
(
'User'
);
app
(
UserRegistration
::
class
)
->
register
([
'email'
=>
'n.widart@gmail.com'
,
'password'
=>
'demo1234'
,
]);
$user
=
$this
->
user
->
find
(
1
);
self
::
assertCount
(
1
,
$this
->
user
->
all
());
self
::
assertEquals
(
'n.widart@gmail.com'
,
$user
->
email
);
self
::
assertEquals
(
'User'
,
$user
->
roles
->
first
()
->
name
);
}
private
function
createRole
(
$name
)
{
return
$this
->
role
->
create
([
'name'
=>
$name
,
'slug'
=>
str_slug
(
$name
),
]);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment