Skip to content
Projects
Groups
Snippets
Help
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project overview
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
301
Merge Requests
38
CI / CD
Security & Compliance
Packages
Wiki
Snippets
Members
Collapse sidebar
Close sidebar
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
dbf0eb01cd2306644b19a831e8095052cb4d5550...0b17a3262da3878e1b83de8f80eab587dc149c22
Source
0b17a3262da3878e1b83de8f80eab587dc149c22
...
Target
dbf0eb01cd2306644b19a831e8095052cb4d5550
Compare
Commits (4)
(refactor) Remove registrations from Boost Di Provider that aren't actually used anywhere -
#1107
· 4e8394fd
Guy Thouret
authored
12 hours ago
4e8394fd
(refactor) Refactor Boost Handler Factory further and add tests -
#1142
· 5c2c857d
Guy Thouret
authored
1 hour ago
5c2c857d
(chore) Fix Boost Network Metrics tests where Mongo was removed -
#1142
· 081e1b27
Guy Thouret
authored
49 minutes ago
081e1b27
(chore) Fix Boost Repository Test where Mongo was removed -
#1142
· 0b17a326
Guy Thouret
authored
47 minutes ago
0b17a326
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
86 additions
and
165 deletions
+86
-165
Controllers/api/v2/boost.php
View file @
0b17a326
...
...
@@ -224,7 +224,7 @@ class boost implements Interfaces\Api
// Validate entity
$boostHandler
=
Core\Boost\Handler\Factory
::
get
Handler
(
ucfirst
(
$pages
[
0
])
);
$boostHandler
=
Core\Boost\Handler\Factory
::
get
(
$pages
[
0
]
);
$isEntityValid
=
$boostHandler
->
validateEntity
(
$entity
);
if
(
!
$isEntityValid
)
{
...
...
This diff is collapsed.
Core/Boost/BoostProvider.php
View file @
0b17a326
...
...
@@ -28,18 +28,10 @@ class BoostProvider extends Di\Provider
return
new
Network\Iterator
();
},
[
'useFactory'
=>
false
]);
$this
->
di
->
bind
(
'Boost\Network\Metrics'
,
function
(
$di
)
{
return
new
Network\Metrics
();
},
[
'useFactory'
=>
false
]);
$this
->
di
->
bind
(
'Boost\Network\Review'
,
function
(
$di
)
{
return
new
Network\Review
();
},
[
'useFactory'
=>
false
]);
$this
->
di
->
bind
(
'Boost\Peer'
,
function
(
$di
)
{
return
new
Peer
();
},
[
'useFactory'
=>
true
]);
$this
->
di
->
bind
(
'Boost\Peer\Review'
,
function
(
$di
)
{
return
new
Peer\Review
();
},
[
'useFactory'
=>
false
]);
...
...
This diff is collapsed.
Core/Boost/Handler/Factory.php
View file @
0b17a326
...
...
@@ -9,13 +9,32 @@ use Minds\Interfaces\BoostHandlerInterface;
*/
class
Factory
{
public
static
function
getHandler
(
$handler
)
:
BoostHandlerInterface
const
HANDLER_CHANNEL
=
'channel'
;
const
HANDLER_CONTENT
=
'content'
;
const
HANDLER_NETWORK
=
'network'
;
const
HANDLER_NEWSFEED
=
'newsfeed'
;
const
HANDLER_PEER
=
'peer'
;
const
HANDLERS
=
[
self
::
HANDLER_CHANNEL
=>
Channel
::
class
,
self
::
HANDLER_CONTENT
=>
Content
::
class
,
self
::
HANDLER_NETWORK
=>
Network
::
class
,
self
::
HANDLER_NEWSFEED
=>
Newsfeed
::
class
,
self
::
HANDLER_PEER
=>
Peer
::
class
];
/**
* @param string $handler
* @return BoostHandlerInterface
* @throws \Exception
*/
public
static
function
get
(
string
$handler
)
:
BoostHandlerInterface
{
$handler
=
ucfirst
(
$handler
);
$handler
=
"Minds
\\
Core
\\
Boost
\\
Handler
\\
$handler
"
;
if
(
class_exists
(
$handler
))
{
return
new
$handler
;
if
(
!
isset
(
self
::
HANDLERS
[
$handler
])
||
!
class_exists
(
self
::
HANDLERS
[
$handler
]))
{
throw
new
\Exception
(
"Handler not found"
);
}
throw
new
\Exception
(
"Handler not found"
);
$class
=
self
::
HANDLERS
[
$handler
];
return
new
$class
;
}
}
This diff is collapsed.
Core/Boost/Network/Metrics.php
View file @
0b17a326
...
...
@@ -7,18 +7,6 @@ use Minds\Helpers;
class
Metrics
{
protected
$type
;
/**
* @param string $type
* @return $this
*/
public
function
setType
(
$type
)
{
$this
->
type
=
strtolower
(
$type
);
return
$this
;
}
/**
* Increments impressions to a given boost
* @param Network $boost
...
...
This diff is collapsed.
Spec/Core/Boost/FactorySpec.php
→
Spec/Core/Boost/
Handler/
FactorySpec.php
View file @
0b17a326
<?php
namespace
Spec\Minds\Core\Boost
;
namespace
Spec\Minds\Core\Boost
\Handler
;
use
Minds\Core\Boost\Handler\Factory
;
use
Minds\Core\Boost\Handler\Newsfeed
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
use
Minds\Core\Data\MongoDB\Client
as
MongoClient
;
class
FactorySpec
extends
ObjectBehavior
{
public
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
'Minds\Core\Boost\Factory'
);
$this
->
shouldHaveType
(
Factory
::
class
);
}
public
function
it_should_
build_a_handler
(
MongoClient
$db
)
public
function
it_should_
return_a_handler
(
)
{
$this
::
build
(
"Newsfeed"
,
Argument
::
any
(),
$db
)
->
shouldHaveType
(
'Minds\Core\Boost\Newsfeed'
);
$this
::
get
(
Factory
::
HANDLER_NEWSFEED
)
->
shouldHaveType
(
Newsfeed
::
class
);
}
public
function
it_should_throw_an_error_if_handler_doesnt_exist
()
{
$this
->
shouldThrow
(
"\Exception"
)
->
during
(
"
build
"
,
[
"FakeBoost"
]);
$this
->
shouldThrow
(
"\Exception"
)
->
during
(
"
get
"
,
[
"FakeBoost"
]);
}
}
This diff is collapsed.
Spec/Core/Boost/Handler/NewsfeedSpec.php
0 → 100644
View file @
0b17a326
<?php
namespace
Spec\Minds\Core\Boost\Handler
;
use
Minds\Core\Blogs\Blog
;
use
Minds\Core\Boost\Handler\Newsfeed
;
use
Minds\Entities\Activity
;
use
Minds\Entities\Image
;
use
Minds\Entities\User
;
use
Minds\Entities\Video
;
use
PhpSpec\ObjectBehavior
;
class
NewsfeedSpec
extends
ObjectBehavior
{
public
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
Newsfeed
::
class
);
}
public
function
it_should_validate_entity
(
Activity
$activity
,
Video
$video
,
Image
$image
,
Blog
$blog
,
User
$user
)
{
$this
->
validateEntity
(
$activity
)
->
shouldReturn
(
true
);
$this
->
validateEntity
(
$video
)
->
shouldReturn
(
true
);
$this
->
validateEntity
(
$image
)
->
shouldReturn
(
true
);
$this
->
validateEntity
(
$blog
)
->
shouldReturn
(
true
);
$this
->
validateEntity
(
$user
)
->
shouldReturn
(
false
);
}
}
This diff is collapsed.
Spec/Core/Boost/Network/MetricsSpec.php
View file @
0b17a326
...
...
@@ -2,56 +2,13 @@
namespace
Spec\Minds\Core\Boost\Network
;
use
Minds\Core\Boost\Repository
;
use
Minds\Core\Data\MongoDB
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Boost\Network\Metrics
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
MetricsSpec
extends
ObjectBehavior
{
public
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
'Minds\Core\Boost\Network\Metrics'
);
}
public
function
it_should_get_backlog_count
(
MongoDB\Client
$mongo
)
{
$mongo
->
count
(
Argument
::
containingString
(
'boost'
),
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
3
);
$this
->
beConstructedWith
(
$mongo
);
$this
->
getBacklogCount
(
'newsfeed'
,
'123'
)
->
shouldReturn
(
3
);
}
public
function
it_should_get_priority_backlog_count
(
MongoDB\Client
$mongo
)
{
$mongo
->
count
(
Argument
::
containingString
(
'boost'
),
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
3
);
$this
->
beConstructedWith
(
$mongo
);
$this
->
getPriorityBacklogCount
(
'newsfeed'
,
'123'
)
->
shouldReturn
(
3
);
}
public
function
it_should_get_backlog_impressions_sum
(
MongoDB\Client
$mongo
)
{
$total
=
new
\stdClass
();
$total
->
total
=
10
;
$result
=
[
'total'
=>
$total
];
$mongo
->
aggregate
(
Argument
::
containingString
(
'boost'
),
Argument
::
any
())
->
shouldBeCalled
()
->
willReturn
(
$result
);
$this
->
beConstructedWith
(
$mongo
);
$this
->
getBacklogImpressionsSum
(
'newsfeed'
)
->
shouldReturn
(
10
);
$this
->
shouldHaveType
(
Metrics
::
class
);
}
}
This diff is collapsed.
Spec/Core/Boost/NewsfeedSpec.php
deleted
100644 → 0
View file @
dbf0eb01
<?php
namespace
Spec\Minds\Core\Boost
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
use
Prophecy\Prophet
;
use
Minds\Entities\User
;
use
Minds\Entities\Boost\Network
;
use
Minds\Core\Data\Call
;
use
Minds\Core\Data\MongoDB\Client
;
use
Minds\Core\Data\Interfaces\ClientInterface
;
class
NewsfeedSpec
extends
ObjectBehavior
{
public
function
let
(
Client
$mongo
,
Call
$db
,
User
$user
)
{
$mongo
->
insert
(
Argument
::
type
(
'string'
),
Argument
::
type
(
'array'
))
->
willReturn
(
"boost_id"
);
//$db->getRow(Argument::type(''))->will
$this
->
beConstructedWith
([],
$mongo
,
$db
);
}
public
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
'Minds\Core\Boost\Newsfeed'
);
}
public
function
it_can_boost_a_post
(
Network
$boost
,
User
$user
,
Client
$mongo
,
Call
$db
)
{
$boost
->
getGuid
()
->
willReturn
(
'foo'
);
$boost
->
getImpressions
()
->
willReturn
(
10
);
$boost
->
getOwner
()
->
willReturn
(
$user
);
$boost
->
getRating
()
->
willReturn
(
1
);
$boost
->
getQuality
()
->
willReturn
(
75
);
$boost
->
getImpressions
()
->
willReturn
(
100
);
$boost
->
getPriorityRate
()
->
willReturn
(
0
);
$boost
->
getCategories
()
->
willReturn
([
'art'
,
'music'
]);
$this
->
boost
(
$boost
)
->
shouldBeString
();
}
}
This diff is collapsed.
Spec/Core/Boost/RepositorySpec.php
View file @
0b17a326
...
...
@@ -245,54 +245,6 @@ class RepositorySpec extends ObjectBehavior
->
shouldReturn
(
false
);
}
// getEntityById()
public
function
it_should_get_a_single_boost_based_on_mongo
()
{
$this
->
_client
->
request
(
Argument
::
type
(
Prepared\Custom
::
class
))
->
shouldBeCalled
()
->
willReturn
([
[
'type'
=>
'network'
,
'data'
=>
[
]
],
]);
$this
->
getEntityById
(
'network'
,
'm2000'
)
->
shouldReturnAnInstanceOf
(
Entities\Boost\Network
::
class
);
}
public
function
it_should_not_get_a_single_boost_based_on_mongo_if_no_type
()
{
$this
->
_client
->
request
(
Argument
::
type
(
Prepared\Custom
::
class
))
->
shouldNotBeCalled
();
$this
->
getEntityById
(
null
,
'm2000'
)
->
shouldReturn
(
false
);
}
public
function
it_should_not_get_a_single_boost_based_on_mongo_if_no_id
()
{
$this
->
_client
->
request
(
Argument
::
type
(
Prepared\Custom
::
class
))
->
shouldNotBeCalled
();
$this
->
getEntityById
(
'network'
,
null
)
->
shouldReturn
(
false
);
}
public
function
it_should_not_get_a_single_boost_based_on_mongo_if_not_exists
()
{
$this
->
_client
->
request
(
Argument
::
type
(
Prepared\Custom
::
class
))
->
shouldBeCalled
()
->
willReturn
([]);
$this
->
getEntityById
(
'network'
,
'm2404'
)
->
shouldReturn
(
false
);
}
// upsert()
public
function
it_should_store_a_boost
()
{
$this
->
_client
->
request
(
Argument
::
type
(
Prepared\Custom
::
class
))
...
...
This diff is collapsed.