Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
461576dc
Commit
461576dc
authored
Aug 17, 2014
by
Mark
Committed by
Qiang Xue
Aug 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added other syntax for and tests for fixture controller
parent
d9cd1a85
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
266 additions
and
0 deletions
+266
-0
FixtureController.php
framework/console/controllers/FixtureController.php
+0
-0
FirstFixture.php
...s/unit/data/console/controllers/fixtures/FirstFixture.php
+19
-0
FixtureStorage.php
...unit/data/console/controllers/fixtures/FixtureStorage.php
+21
-0
GlobalFixture.php
.../unit/data/console/controllers/fixtures/GlobalFixture.php
+20
-0
SecondFixture.php
.../unit/data/console/controllers/fixtures/SecondFixture.php
+19
-0
FixtureControllerTest.php
...t/framework/console/controllers/FixtureControllerTest.php
+187
-0
No files found.
framework/console/controllers/FixtureController.php
View file @
461576dc
This diff is collapsed.
Click to expand it.
tests/unit/data/console/controllers/fixtures/FirstFixture.php
0 → 100644
View file @
461576dc
<?php
namespace
yiiunit\data\console\controllers\fixtures
;
use
yii\test\Fixture
;
class
FirstFixture
extends
Fixture
{
public
function
load
()
{
FixtureStorage
::
$firstFixtureData
[]
=
'some data set for first fixture'
;
}
public
function
unload
()
{
FixtureStorage
::
$firstFixtureData
=
[];
}
}
tests/unit/data/console/controllers/fixtures/FixtureStorage.php
0 → 100644
View file @
461576dc
<?php
namespace
yiiunit\data\console\controllers\fixtures
;
class
FixtureStorage
{
public
static
$globalFixturesData
=
[];
public
static
$firstFixtureData
=
[];
public
static
$secondFixtureData
=
[];
public
static
function
clear
()
{
static
::
$globalFixturesData
=
[];
static
::
$firstFixtureData
=
[];
static
::
$secondFixtureData
=
[];
}
}
tests/unit/data/console/controllers/fixtures/GlobalFixture.php
0 → 100644
View file @
461576dc
<?php
namespace
yiiunit\data\console\controllers\fixtures
;
use
yii\test\Fixture
;
class
GlobalFixture
extends
Fixture
{
public
function
load
()
{
FixtureStorage
::
$globalFixturesData
[]
=
'some data set for global fixture'
;
}
public
function
unload
()
{
FixtureStorage
::
$globalFixturesData
=
[];
}
}
tests/unit/data/console/controllers/fixtures/SecondFixture.php
0 → 100644
View file @
461576dc
<?php
namespace
yiiunit\data\console\controllers\fixtures
;
use
yii\test\Fixture
;
class
SecondFixture
extends
Fixture
{
public
function
load
()
{
FixtureStorage
::
$secondFixtureData
[]
=
'some data set for second fixture'
;
}
public
function
unload
()
{
FixtureStorage
::
$secondFixtureData
=
[];
}
}
tests/unit/framework/console/controllers/FixtureControllerTest.php
0 → 100644
View file @
461576dc
<?php
namespace
yiiunit\framework\console\controllers
;
use
Yii
;
use
yiiunit\TestCase
;
use
yiiunit\data\console\controllers\fixtures\FixtureStorage
;
use
yii\console\controllers\FixtureController
;
/**
* Unit test for [[\yii\console\controllers\FixtureController]].
* @see MigrateController
*
* @group console
*/
class
FixtureControllerTest
extends
TestCase
{
/**
* @var \yiiunit\framework\console\controllers\FixtureConsoledController
*/
private
$_fixtureController
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
_fixtureController
=
Yii
::
createObject
([
'class'
=>
'yiiunit\framework\console\controllers\FixtureConsoledController'
,
'interactive'
=>
false
,
'globalFixtures'
=>
[],
'namespace'
=>
'yiiunit\data\console\controllers\fixtures'
,
],[
null
,
null
]);
//id and module are null
}
protected
function
tearDown
()
{
$this
->
_fixtureController
=
null
;
FixtureStorage
::
clear
();
parent
::
tearDown
();
}
public
function
testLoadGlobalFixture
()
{
$this
->
_fixtureController
->
globalFixtures
=
[
'\yiiunit\data\console\controllers\fixtures\Global'
];
$this
->
_fixtureController
->
actionLoad
(
'First'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
}
public
function
testUnloadGlobalFixture
()
{
$this
->
_fixtureController
->
globalFixtures
=
[
'\yiiunit\data\console\controllers\fixtures\Global'
];
FixtureStorage
::
$globalFixturesData
[]
=
'some seeded global fixture data'
;
FixtureStorage
::
$firstFixtureData
[]
=
'some seeded first fixture data'
;
$this
->
assertCount
(
1
,
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
$this
->
_fixtureController
->
actionUnload
(
'First'
);
$this
->
assertEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be unloaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be unloaded'
);
}
public
function
testLoadAll
()
{
$this
->
assertEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be empty'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be empty'
);
$this
->
assertEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should be empty'
);
$this
->
_fixtureController
->
actionLoad
(
'all'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$secondFixtureData
,
'second fixture data should be loaded'
);
}
public
function
testUnloadAll
()
{
FixtureStorage
::
$globalFixturesData
[]
=
'some seeded global fixture data'
;
FixtureStorage
::
$firstFixtureData
[]
=
'some seeded first fixture data'
;
FixtureStorage
::
$secondFixtureData
[]
=
'some seeded second fixture data'
;
$this
->
assertCount
(
1
,
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$secondFixtureData
,
'second fixture data should be loaded'
);
$this
->
_fixtureController
->
actionUnload
(
'all'
);
$this
->
assertEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should be unloaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be unloaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should be unloaded'
);
}
public
function
testLoadParticularExceptOnes
()
{
$this
->
_fixtureController
->
actionLoad
(
'First'
,
'-Second'
,
'-Global'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should not be loaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should not be loaded'
);
}
public
function
testUnloadParticularExceptOnes
()
{
FixtureStorage
::
$globalFixturesData
[]
=
'some seeded global fixture data'
;
FixtureStorage
::
$firstFixtureData
[]
=
'some seeded first fixture data'
;
FixtureStorage
::
$secondFixtureData
[]
=
'some seeded second fixture data'
;
$this
->
_fixtureController
->
actionUnload
(
'First'
,
'-Second'
,
'-Global'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be unloaded'
);
$this
->
assertNotEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should not be unloaded'
);
$this
->
assertNotEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should not be unloaded'
);
}
public
function
testLoadAllExceptOnes
()
{
$this
->
_fixtureController
->
actionLoad
(
'all'
,
'-Second'
,
'-Global'
);
$this
->
assertCount
(
1
,
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be loaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should not be loaded'
);
$this
->
assertEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should not be loaded'
);
}
public
function
testUnloadAllExceptOnes
()
{
FixtureStorage
::
$globalFixturesData
[]
=
'some seeded global fixture data'
;
FixtureStorage
::
$firstFixtureData
[]
=
'some seeded first fixture data'
;
FixtureStorage
::
$secondFixtureData
[]
=
'some seeded second fixture data'
;
$this
->
_fixtureController
->
actionUnload
(
'all'
,
'-Second'
,
'-Global'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should be unloaded'
);
$this
->
assertNotEmpty
(
FixtureStorage
::
$globalFixturesData
,
'global fixture data should not be unloaded'
);
$this
->
assertNotEmpty
(
FixtureStorage
::
$secondFixtureData
,
'second fixture data should not be unloaded'
);
}
public
function
testNothingToLoadParticularExceptOnes
()
{
$this
->
_fixtureController
->
actionLoad
(
'First'
,
'-First'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should not be loaded'
);
}
public
function
testNothingToUnloadParticularExceptOnes
()
{
$this
->
_fixtureController
->
actionUnload
(
'First'
,
'-First'
);
$this
->
assertEmpty
(
FixtureStorage
::
$firstFixtureData
,
'first fixture data should not be loaded'
);
}
/**
* @expectedException \yii\console\Exception
*/
public
function
testNoFixturesWereFoundInLoad
()
{
$this
->
_fixtureController
->
actionLoad
(
'NotExistingFixture'
);
}
/**
* @expectedException \yii\console\Exception
*/
public
function
testNoFixturesWereFoundInUnload
()
{
$this
->
_fixtureController
->
actionUnload
(
'NotExistingFixture'
);
}
}
class
FixtureConsoledController
extends
FixtureController
{
public
function
stdout
(
$string
)
{
}
}
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