Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
3dbfbdaf
Commit
3dbfbdaf
authored
9 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
allow moving common test logic into traits
parent
67893ca8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/lib/connector/sabre/requesttest/requesttest.php
+4
-13
4 additions, 13 deletions
tests/lib/connector/sabre/requesttest/requesttest.php
tests/lib/testcase.php
+32
-1
32 additions, 1 deletion
tests/lib/testcase.php
tests/lib/traits/usertrait.php
+32
-0
32 additions, 0 deletions
tests/lib/traits/usertrait.php
with
68 additions
and
14 deletions
tests/lib/connector/sabre/requesttest/requesttest.php
+
4
−
13
View file @
3dbfbdaf
...
...
@@ -16,12 +16,10 @@ use OC\Files\View;
use
OCP\IUser
;
use
Sabre\HTTP\Request
;
use
Test\TestCase
;
use
Test\Traits\UserTrait
;
abstract
class
RequestTest
extends
TestCase
{
/**
* @var \OC_User_Dummy
*/
protected
$userBackend
;
use
UserTrait
;
/**
* @var \OCP\Files\Config\IMountProvider[]
...
...
@@ -65,8 +63,6 @@ abstract class RequestTest extends TestCase {
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
userBackend
=
new
\OC_User_Dummy
();
\OC
::
$server
->
getUserManager
()
->
registerBackend
(
$this
->
userBackend
);
$this
->
serverFactory
=
new
ServerFactory
(
\OC
::
$server
->
getConfig
(),
...
...
@@ -78,15 +74,10 @@ abstract class RequestTest extends TestCase {
);
}
protected
function
tearDown
()
{
parent
::
tearDown
();
\OC
::
$server
->
getUserManager
()
->
removeBackend
(
$this
->
userBackend
);
}
protected
function
setupUser
(
$name
,
$password
)
{
$this
->
userBackend
->
createUser
(
$name
,
$password
);
$this
->
createUser
(
$name
,
$password
);
\OC
::
$server
->
getMountProviderCollection
()
->
registerProvider
(
$this
->
getMountProvider
(
$name
,
[
'/'
.
$name
=>
new
Temporary
()
'/'
.
$name
=>
'\OC\Files\Storage\
Temporary
'
]));
$this
->
loginAsUser
(
$name
);
return
new
View
(
'/'
.
$name
.
'/files'
);
...
...
This diff is collapsed.
Click to expand it.
tests/lib/testcase.php
+
32
−
1
View file @
3dbfbdaf
...
...
@@ -32,21 +32,52 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
*/
private
$commandBus
;
protected
function
getTestTraits
()
{
$traits
=
[];
$class
=
$this
;
do
{
$traits
=
array_merge
(
class_uses
(
$class
),
$traits
);
}
while
(
$class
=
get_parent_class
(
$class
));
foreach
(
$traits
as
$trait
=>
$same
)
{
$traits
=
array_merge
(
class_uses
(
$trait
),
$traits
);
}
$traits
=
array_unique
(
$traits
);
return
array_filter
(
$traits
,
function
(
$trait
)
{
return
substr
(
$trait
,
0
,
5
)
===
'Test\\'
;
});
}
protected
function
setUp
()
{
// overwrite the command bus with one we can run ourselves
$this
->
commandBus
=
new
QueueBus
();
\OC
::
$server
->
registerService
(
'AsyncCommandBus'
,
function
()
{
return
$this
->
commandBus
;
});
$traits
=
$this
->
getTestTraits
();
foreach
(
$traits
as
$trait
)
{
$methodName
=
'setUp'
.
basename
(
str_replace
(
'\\'
,
'/'
,
$trait
));
if
(
method_exists
(
$this
,
$methodName
))
{
call_user_func
([
$this
,
$methodName
]);
}
}
}
protected
function
tearDown
()
{
$hookExceptions
=
\OC_Hook
::
$thrownExceptions
;
\OC_Hook
::
$thrownExceptions
=
[];
\OC
::
$server
->
getLockingProvider
()
->
releaseAll
();
if
(
!
empty
(
$hookExceptions
))
{
if
(
!
empty
(
$hookExceptions
))
{
throw
$hookExceptions
[
0
];
}
$traits
=
$this
->
getTestTraits
();
foreach
(
$traits
as
$trait
)
{
$methodName
=
'tearDown'
.
basename
(
str_replace
(
'\\'
,
'/'
,
$trait
));
if
(
method_exists
(
$this
,
$methodName
))
{
call_user_func
([
$this
,
$methodName
]);
}
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
tests/lib/traits/usertrait.php
0 → 100644
+
32
−
0
View file @
3dbfbdaf
<?php
/**
* Copyright (c) 2015 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace
Test\Traits
;
/**
* Allow creating users in a temporary backend
*/
trait
UserTrait
{
/**
* @var \OC_User_Dummy|\OCP\UserInterface
*/
protected
$userBackend
;
protected
function
createUser
(
$name
,
$password
)
{
$this
->
userBackend
->
createUser
(
$name
,
$password
);
}
protected
function
setUpUserTrait
()
{
$this
->
userBackend
=
new
\OC_User_Dummy
();
\OC
::
$server
->
getUserManager
()
->
registerBackend
(
$this
->
userBackend
);
}
protected
function
tearDownUserTrait
()
{
\OC
::
$server
->
getUserManager
()
->
removeBackend
(
$this
->
userBackend
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment