Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pôle IS
Bundles Symfony 2
maybe
Commits
4495c462
Commit
4495c462
authored
Apr 10, 2019
by
Guillaume Perréal
Browse files
Added some testdox.
parent
026682b0
Changes
5
Hide whitespace changes
Inline
Side-by-side
composer.json
View file @
4495c462
...
...
@@ -70,7 +70,7 @@
"test:phpcpd"
:
"vendor/bin/phpcpd --fuzzy src tests"
,
"test:phpmd"
:
"vendor/bin/phpmd src,tests text ./phpmd-ruleset.xml"
,
"test:phpstan"
:
"vendor/bin/phpstan analyse --ansi --no-progress src tests"
,
"test:phpunit"
:
"vendor/bin/phpunit"
,
"test:phpunit"
:
"vendor/bin/phpunit
--colors=always --testdox
"
,
"test:composer-validate"
:
"composer validate"
,
"test:composer-require"
:
"vendor/bin/composer-require-checker check"
,
"test:security"
:
"test '!' -s composer.lock || vendor/bin/security-checker security:check"
...
...
src/Maybe.php
View file @
4495c462
...
...
@@ -93,12 +93,11 @@ abstract class Maybe implements \IteratorAggregate
{
Assertion
::
allIsInstanceOf
(
$maybes
,
self
::
class
);
return
array_merge
(
...
array_map
(
static
function
(
Maybe
$maybe
)
{
return
$maybe
->
toArray
();
},
$maybes
return
array_map
(
static
function
(
Just
$just
)
{
return
$just
->
value
();
},
array_filter
(
$maybes
,
static
function
(
Maybe
$maybe
)
{
return
$maybe
instanceof
Just
;
}
)
);
}
...
...
tests/Maybe/JustTest.php
View file @
4495c462
...
...
@@ -13,6 +13,9 @@ use PHPUnit\Framework\TestCase;
*/
class
JustTest
extends
TestCase
{
/**
* @testdox ->map() should call the callback with the value and pass the result.
*/
public
function
testMap
()
{
self
::
assertEquals
(
...
...
@@ -25,6 +28,9 @@ class JustTest extends TestCase
);
}
/**
* @testdox ->resolve() should call the first callback with the value and pass the result.
*/
public
function
testResolve
()
{
self
::
assertEquals
(
...
...
@@ -40,11 +46,17 @@ class JustTest extends TestCase
);
}
/**
* @testdox ->toArray() should return an array of one item.
*/
public
function
testToArray
()
{
self
::
assertEquals
([
2
],
Just
::
from
(
2
)
->
toArray
());
}
/**
* @testdox ->value() should return the value.
*/
public
function
testValue
()
{
self
::
assertEquals
(
...
...
@@ -53,26 +65,41 @@ class JustTest extends TestCase
);
}
/**
* @testdox ->filter() should filter should return Just when the predicate returns true.
*/
public
function
testFilterAccepted
()
{
self
::
assertEquals
([
2
],
Just
::
from
(
2
)
->
filter
(
'is_integer'
)
->
toArray
());
}
/**
* @testdox ->filter() should filter should return Nothing when the predicate returns false.
*/
public
function
testFilterRejected
()
{
self
::
assertNotEquals
([
2
],
Just
::
from
(
2
)
->
filter
(
'is_string'
)
->
toArray
());
}
/**
* @testdox ->valueOr() should return the value.
*/
public
function
testValueOr
()
{
self
::
assertEquals
(
2
,
Just
::
from
(
2
)
->
valueOr
(
5
));
}
/**
* @testdox ->value() should return the value.
*/
public
function
testConcat
()
{
self
::
assertEquals
(
2
,
Just
::
from
(
2
)
->
concat
(
Just
::
from
(
6
))
->
value
());
}
/**
* @testdox ->getIterator() should return an Iterator with a single item.
*/
public
function
testGetIterator
()
{
$values
=
\
iterator_to_array
(
Just
::
from
(
2
));
...
...
tests/Maybe/NothingTest.php
View file @
4495c462
...
...
@@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase;
*/
class
NothingTest
extends
TestCase
{
/**
* @testdox ->map() should ignore its argument and return itself.
*/
public
function
testMap
()
{
self
::
assertEquals
(
...
...
@@ -27,6 +30,9 @@ class NothingTest extends TestCase
);
}
/**
* @testdox ->resolve() should always call the second callback.
*/
public
function
testResolve
()
{
self
::
assertEquals
(
...
...
@@ -42,11 +48,17 @@ class NothingTest extends TestCase
);
}
/**
* @testdox ->toArray() should return an empty array.
*/
public
function
testToArray
()
{
self
::
assertEquals
([],
Nothing
::
instance
()
->
toArray
());
}
/**
* @testdox ->value() should throw a NothingException.
*/
public
function
testValue
()
{
$this
->
expectException
(
NothingException
::
class
);
...
...
@@ -54,21 +66,33 @@ class NothingTest extends TestCase
Nothing
::
instance
()
->
value
();
}
/**
* @testdox ->filter() should ignore its argument and return itself.
*/
public
function
testFilter
()
{
self
::
assertEquals
([],
Nothing
::
instance
()
->
filter
(
'is_string'
)
->
toArray
());
}
/**
* @testdox ->valueOr() should return its argument.
*/
public
function
testValueOr
()
{
self
::
assertEquals
(
2
,
Nothing
::
instance
()
->
valueOr
(
2
));
}
/**
* @testdox ->concat() should return its argument.
*/
public
function
testConcat
()
{
self
::
assertEquals
([
2
],
Nothing
::
instance
()
->
concat
(
Just
::
from
(
2
))
->
toArray
());
}
/**
* @testdox ->getIterator() should return an empty Iterator.
*/
public
function
testGetIterator
()
{
$values
=
\
iterator_to_array
(
Nothing
::
instance
());
...
...
tests/MaybeTest.php
View file @
4495c462
...
...
@@ -15,30 +15,45 @@ use PHPUnit\Framework\TestCase;
*/
class
MaybeTest
extends
TestCase
{
/**
* @testdox ::just() should wrap any value with Just::from.
*/
public
function
testJustFromScalar
()
{
self
::
assertEquals
(
42
,
Maybe
::
just
(
42
)
->
value
());
}
/**
* @testdox ::just() should return any Just instance as is.
*/
public
function
testJustFromJust
()
{
self
::
assertEquals
(
42
,
Maybe
::
just
(
Just
::
from
(
42
))
->
value
());
}
/**
* @testdox ::just() should return Nothing as is.
*/
public
function
testJustFromNothing
()
{
self
::
assertEquals
([],
Maybe
::
just
(
Nothing
::
instance
())
->
toArray
());
}
/**
* @testdox ::nothing() should return Nothing.
*/
public
function
testNothing
()
{
self
::
assertEquals
([],
Maybe
::
nothing
()
->
toArray
());
}
/**
* @testdox ::some() should the value of Justs.
*/
public
function
testSome
()
{
self
::
assertEquals
(
[
5
,
'x'
],
[
1
=>
5
,
3
=>
'x'
],
Maybe
::
some
(
[
Maybe
::
nothing
(),
...
...
@@ -51,6 +66,9 @@ class MaybeTest extends TestCase
);
}
/**
* @testdox ::run() should pass back Just values to the generator.
*/
public
function
testRunJusts
()
{
$result
=
Maybe
::
run
(
static
function
()
{
...
...
@@ -64,6 +82,9 @@ class MaybeTest extends TestCase
self
::
assertEquals
(
20
,
$result
->
valueOr
(
0
));
}
/**
* @testdox ::run() should interrupt the generator when yielded Nothing.
*/
public
function
testRunNothing
()
{
$result
=
Maybe
::
run
(
static
function
()
{
...
...
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