Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (2)
Restore a conditional exception to Boost Manager::getList; Refactor it's spec test a little
· b508c766
Guy Thouret
authored
Nov 21, 2019
b508c766
Lint Boost Manager
· 09cddca5
Guy Thouret
authored
Nov 21, 2019
09cddca5
Hide whitespace changes
Inline
Side-by-side
Core/Boost/Network/Manager.php
View file @
09cddca5
...
...
@@ -70,7 +70,8 @@ class Manager
if
(
$opts
[
'useElastic'
])
{
$response
=
$this
->
elasticRepository
->
getList
(
$opts
);
if
(
$this
->
optStateIsUsedAndValid
(
$opts
))
{
// TODO: Check if it is *really* necessary to re fetch the boosts from cassandra ??
if
(
$this
->
optStateIsUsedAndValid
(
$opts
)
&&
$opts
[
'state'
]
!==
self
::
OPT_STATEQUERY_APPROVED
)
{
$opts
[
'guids'
]
=
array_map
(
function
(
$boost
)
{
return
$boost
->
getGuid
();
},
$response
->
toArray
());
...
...
@@ -114,7 +115,7 @@ class Manager
protected
function
optStateIsValid
(
array
$opts
):
bool
{
return
in_array
(
$opts
[
'state'
],
self
::
VALID_OPT_STATEQUERY
);
return
in_array
(
$opts
[
'state'
],
self
::
VALID_OPT_STATEQUERY
,
true
);
}
/**
...
...
Spec/Core/Boost/Network/ManagerSpec.php
View file @
09cddca5
...
...
@@ -19,7 +19,7 @@ use Minds\Core\Di\Di;
class
ManagerSpec
extends
ObjectBehavior
{
/** @var CassandraRepository */
private
$
r
epository
;
private
$
cassandraR
epository
;
/** @var ElasticRepository */
private
$elasticRepository
;
/** @var EntitiesBuilder */
...
...
@@ -28,13 +28,13 @@ class ManagerSpec extends ObjectBehavior
private
$guidBuilder
;
public
function
let
(
CassandraRepository
$
r
epository
,
CassandraRepository
$
cassandraR
epository
,
ElasticRepository
$elasticRepository
,
EntitiesBuilder
$entitiesBuilder
,
GuidBuilder
$guidBuilder
)
{
$this
->
beConstructedWith
(
$
r
epository
,
$elasticRepository
,
$entitiesBuilder
,
$guidBuilder
);
$this
->
r
epository
=
$
r
epository
;
$this
->
beConstructedWith
(
$
cassandraR
epository
,
$elasticRepository
,
$entitiesBuilder
,
$guidBuilder
);
$this
->
cassandraR
epository
=
$
cassandraR
epository
;
$this
->
elasticRepository
=
$elasticRepository
;
$this
->
entitiesBuilder
=
$entitiesBuilder
;
$this
->
guidBuilder
=
$guidBuilder
;
...
...
@@ -47,7 +47,7 @@ class ManagerSpec extends ObjectBehavior
public
function
it_should_return_a_list_of_boosts_to_review
()
{
$response
=
new
Response
([
$response
Obj
=
new
Response
([
(
new
Boost
)
->
setGuid
(
1
)
->
setEntityGuid
(
123
)
...
...
@@ -61,19 +61,19 @@ class ManagerSpec extends ObjectBehavior
]);
$this
->
elasticRepository
->
getList
([
'state'
=>
'review'
,
'state'
=>
Manager
::
OPT_STATEQUERY_REVIEW
,
'useElastic'
=>
true
,
])
->
shouldBeCalled
()
->
willReturn
(
$response
);
->
willReturn
(
$response
Obj
);
$this
->
r
epository
->
getList
([
'state'
=>
'review'
,
$this
->
cassandraR
epository
->
getList
([
'state'
=>
Manager
::
OPT_STATEQUERY_REVIEW
,
'useElastic'
=>
true
,
'guids'
=>
[
1
,
2
],
])
->
shouldBeCalled
()
->
willReturn
(
$response
);
->
willReturn
(
$response
Obj
);
$this
->
entitiesBuilder
->
single
(
123
)
->
shouldBeCalled
()
->
willReturn
((
new
Activity
)
->
set
(
'guid'
,
123
));
$this
->
entitiesBuilder
->
single
(
1
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
1
));
...
...
@@ -81,7 +81,7 @@ class ManagerSpec extends ObjectBehavior
$this
->
entitiesBuilder
->
single
(
2
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
2
));
$response
=
$this
->
getList
([
'state'
=>
'review'
,
'state'
=>
Manager
::
OPT_STATEQUERY_REVIEW
,
]);
$response
[
0
]
->
getEntity
()
->
getGuid
()
->
shouldBe
(
123
);
...
...
@@ -95,7 +95,7 @@ class ManagerSpec extends ObjectBehavior
public
function
it_should_return_a_list_of_boosts_to_deliver
()
{
$response
=
new
Response
([
$response
Obj
=
new
Response
([
(
new
Boost
)
->
setEntityGuid
(
123
)
->
setImpressions
(
1000
)
...
...
@@ -105,12 +105,11 @@ class ManagerSpec extends ObjectBehavior
->
setImpressions
(
100
)
->
setOwnerGuid
(
2
)
]);
$this
->
elasticRepository
->
getList
([
'state'
=>
'approved'
,
'state'
=>
Manager
::
OPT_STATEQUERY_APPROVED
,
'useElastic'
=>
true
,
])
->
shouldBeCalled
()
->
willReturn
(
$response
);
])
->
shouldBeCalled
()
->
willReturn
(
$responseObj
);
$this
->
entitiesBuilder
->
single
(
123
)
->
shouldBeCalled
()
->
willReturn
((
new
Activity
)
->
set
(
'guid'
,
123
));
$this
->
entitiesBuilder
->
single
(
1
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
1
));
...
...
@@ -118,7 +117,7 @@ class ManagerSpec extends ObjectBehavior
$this
->
entitiesBuilder
->
single
(
2
)
->
shouldBeCalled
()
->
willReturn
((
new
User
)
->
set
(
'guid'
,
2
));
$response
=
$this
->
getList
([
'state'
=>
'approved'
,
'state'
=>
Manager
::
OPT_STATEQUERY_APPROVED
,
'useElastic'
=>
true
,
]);
...
...
@@ -144,7 +143,7 @@ class ManagerSpec extends ObjectBehavior
->
setOwnerGuid
(
2
)
]);
$this
->
r
epository
->
getList
([
$this
->
cassandraR
epository
->
getList
([
'state'
=>
null
,
'guids'
=>
[
123
,
456
],
'useElastic'
=>
false
,
...
...
@@ -177,7 +176,7 @@ class ManagerSpec extends ObjectBehavior
$boost
->
getGuid
()
->
shouldbeCalled
()
->
willReturn
(
null
);
$boost
->
setGuid
(
1
)
->
shouldBeCalled
();
$this
->
r
epository
->
add
(
$boost
)
->
shouldBeCalled
();
$this
->
cassandraR
epository
->
add
(
$boost
)
->
shouldBeCalled
();
$this
->
elasticRepository
->
add
(
$boost
)
->
shouldBeCalled
();
$this
->
add
(
$boost
)
->
shouldReturn
(
true
);
...
...
@@ -185,7 +184,7 @@ class ManagerSpec extends ObjectBehavior
public
function
it_should_update_a_boost
(
Boost
$boost
)
{
$this
->
r
epository
->
update
(
$boost
,
[
'@timestamp'
])
->
shouldBeCalled
();
$this
->
cassandraR
epository
->
update
(
$boost
,
[
'@timestamp'
])
->
shouldBeCalled
();
$this
->
elasticRepository
->
update
(
$boost
,
[
'@timestamp'
])
->
shouldBeCalled
();
$this
->
update
(
$boost
,
[
'@timestamp'
]);
...
...
@@ -210,7 +209,7 @@ class ManagerSpec extends ObjectBehavior
$this
->
elasticRepository
->
getList
(
$params
)
->
shouldBeCalled
()
->
willReturn
(
$response
);
$response
->
toArray
()
->
shouldbeCalled
()
->
willReturn
([
$boost
]);
$this
->
r
epository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$response
);
$this
->
cassandraR
epository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$response
);
$boost
->
getGuid
()
->
shouldBeCalled
()
->
willReturn
(
'9012'
);
$boost
->
getType
()
->
shouldBeCalled
()
->
willReturn
(
'newsfeed'
);
...
...
@@ -250,7 +249,7 @@ class ManagerSpec extends ObjectBehavior
];
$this
->
elasticRepository
->
getList
(
$params
)
->
shouldBeCalled
()
->
willReturn
(
$response
);
$response
->
toArray
()
->
shouldbeCalled
()
->
willReturn
([
$boost
]);
$this
->
r
epository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$response
);
$this
->
cassandraR
epository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$response
);
$boost
->
getGuid
()
->
shouldBeCalled
()
->
willReturn
(
'9012'
);
$boost
->
getEntityGuid
()
->
shouldBeCalled
()
->
willReturn
(
'1234'
);
...
...
@@ -350,7 +349,7 @@ class ManagerSpec extends ObjectBehavior
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$existingBoosts
,
''
));
$this
->
r
epository
->
getList
(
Argument
::
any
())
$this
->
cassandraR
epository
->
getList
(
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
new
Response
(
$existingBoosts
));
...
...