Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
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
sinan
mongo-php-library
Commits
af42e76b
Commit
af42e76b
authored
Mar 18, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move pedantic method declaration test to its own file
Related to:
495e46d4
parent
97ab718e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
32 deletions
+63
-32
CollectionTest.php
tests/CollectionTest.php
+0
-32
PedantryTest.php
tests/PedantryTest.php
+63
-0
No files found.
tests/CollectionTest.php
deleted
100644 → 0
View file @
97ab718e
<?php
namespace
MongoDB\Tests
;
use
ReflectionClass
;
use
ReflectionMethod
;
class
CollectionTest
extends
TestCase
{
public
function
testMethodOrder
()
{
$class
=
new
ReflectionClass
(
'MongoDB\Collection'
);
$filters
=
array
(
'public'
=>
ReflectionMethod
::
IS_PUBLIC
,
'protected'
=>
ReflectionMethod
::
IS_PROTECTED
,
'private'
=>
ReflectionMethod
::
IS_PRIVATE
,
);
foreach
(
$filters
as
$visibility
=>
$filter
)
{
$methods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$class
->
getMethods
(
$filter
)
);
$sortedMethods
=
$methods
;
sort
(
$sortedMethods
);
$this
->
assertEquals
(
$methods
,
$sortedMethods
,
sprintf
(
'%s methods are declared alphabetically'
,
ucfirst
(
$visibility
)));
}
}
}
tests/PedantryTest.php
0 → 100644
View file @
af42e76b
<?php
namespace
MongoDB\Tests
;
use
RecursiveDirectoryIterator
;
use
RecursiveIteratorIterator
;
use
ReflectionClass
;
use
ReflectionMethod
;
use
RegexIterator
;
/**
* Pedantic tests that have nothing to do with functional correctness.
*/
class
PedantryTest
extends
\PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideProjectClassNames
*/
public
function
testMethodsAreOrderedAlphabeticallyByVisibility
(
$className
)
{
$class
=
new
ReflectionClass
(
$className
);
$methods
=
$class
->
getMethods
();
$getSortValue
=
function
(
ReflectionMethod
$method
)
{
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PRIVATE
)
{
return
'2'
.
$method
->
getName
();
}
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PROTECTED
)
{
return
'1'
.
$method
->
getName
();
}
if
(
$method
->
getModifiers
()
&
ReflectionMethod
::
IS_PUBLIC
)
{
return
'0'
.
$method
->
getName
();
}
};
$sortedMethods
=
$methods
;
usort
(
$sortedMethods
,
function
(
ReflectionMethod
$a
,
ReflectionMethod
$b
)
use
(
$getSortValue
)
{
return
strcasecmp
(
$getSortValue
(
$a
),
$getSortValue
(
$b
));
}
);
$methods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$methods
);
$sortedMethods
=
array_map
(
function
(
ReflectionMethod
$method
)
{
return
$method
->
getName
();
},
$sortedMethods
);
$this
->
assertEquals
(
$sortedMethods
,
$methods
);
}
public
function
provideProjectClassNames
()
{
$classNames
=
array
();
$srcDir
=
realpath
(
__DIR__
.
'/../src/'
);
$files
=
new
RegexIterator
(
new
RecursiveIteratorIterator
(
new
RecursiveDirectoryIterator
(
$srcDir
)),
'/\.php$/i'
);
foreach
(
$files
as
$file
)
{
$classNames
[][]
=
'MongoDB\\'
.
str_replace
(
DIRECTORY_SEPARATOR
,
'\\'
,
substr
(
$file
->
getRealPath
(),
strlen
(
$srcDir
)
+
1
,
-
4
));
}
return
$classNames
;
}
}
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