Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
235
Issues
235
List
Boards
Labels
Service Desk
Milestones
Merge Requests
34
Merge Requests
34
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
7192407da94a51565b33e804e43a10665518cfee...1504e91121366cfcb86eb6550a241f8cabc62cb5
Source
1504e91121366cfcb86eb6550a241f8cabc62cb5
Select Git revision
...
Target
7192407da94a51565b33e804e43a10665518cfee
Select Git revision
Compare
Commits (2)
(chore) Add spec test for boost campaign urn delegate -
#631
· e491db10
Guy Thouret
authored
1 day ago
e491db10
(chore) Add spec test for boost campaign delegate NormalizeHashtagsDelegate -
#631
· 1504e911
Guy Thouret
authored
1 day ago
1504e911
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
29 deletions
+118
-29
Core/Boost/Campaigns/Delegates/CampaignUrnDelegate.php
Core/Boost/Campaigns/Delegates/CampaignUrnDelegate.php
+4
-14
Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegate.php
Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegate.php
+5
-14
Spec/Core/Boost/Campaigns/Delegates/CampaignUrnDelegateSpec.php
...ore/Boost/Campaigns/Delegates/CampaignUrnDelegateSpec.php
+27
-1
Spec/Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegateSpec.php
...ost/Campaigns/Delegates/NormalizeHashtagsDelegateSpec.php
+82
-0
No files found.
Core/Boost/Campaigns/Delegates/CampaignUrnDelegate.php
View file @
1504e911
<?php
/**
* CampaignUrnDelegate
* @author edgebal
*/
namespace
Minds\Core\Boost\Campaigns\Delegates
;
...
...
@@ -20,9 +16,8 @@ class CampaignUrnDelegate
* CampaignUrnDelegate constructor.
* @param GuidBuilder $guid
*/
public
function
__construct
(
$guid
=
null
)
{
public
function
__construct
(
?
GuidBuilder
$guid
=
null
)
{
$this
->
guid
=
$guid
?:
Di
::
_
()
->
get
(
'Guid'
);
}
...
...
@@ -31,18 +26,13 @@ class CampaignUrnDelegate
* @return Campaign
* @throws CampaignException
*/
public
function
onCreate
(
Campaign
$campaign
)
public
function
onCreate
(
Campaign
$campaign
)
:
Campaign
{
if
(
$campaign
->
getUrn
())
{
throw
new
CampaignException
(
'Campaign already has an URN'
);
}
$guid
=
$this
->
guid
->
build
();
$urn
=
"urn:campaign:
{
$guid
}
"
;
$campaign
->
setUrn
(
$urn
);
return
$campaign
;
return
$campaign
->
setUrn
(
"urn:campaign:
{
$guid
}
"
);
}
}
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegate.php
View file @
1504e911
<?php
/**
* NormalizeHashtagsDelegate
* @author edgebal
*/
namespace
Minds\Core\Boost\Campaigns\Delegates
;
...
...
@@ -16,7 +12,7 @@ class NormalizeHashtagsDelegate
* @return Campaign
* @throws CampaignException
*/
public
function
onCreate
(
Campaign
$campaign
)
public
function
onCreate
(
Campaign
$campaign
)
:
Campaign
{
$hashtags
=
$campaign
->
getHashtags
();
...
...
@@ -29,13 +25,10 @@ class NormalizeHashtagsDelegate
},
$hashtags
))));
if
(
count
(
$hashtags
)
>
5
)
{
throw
new
CampaignException
(
'Campaigns
should have 5 hashtags or les
s'
);
throw
new
CampaignException
(
'Campaigns
have a maximum of 5 hashtag
s'
);
}
$campaign
->
setHashtags
(
$hashtags
);
return
$campaign
;
return
$campaign
->
setHashtags
(
$hashtags
);
}
/**
...
...
@@ -44,11 +37,9 @@ class NormalizeHashtagsDelegate
* @return Campaign
* @throws CampaignException
*/
public
function
onUpdate
(
Campaign
$campaign
,
Campaign
$campaignRef
)
public
function
onUpdate
(
Campaign
$campaign
,
Campaign
$campaignRef
)
:
Campaign
{
$campaign
->
setHashtags
(
$campaignRef
->
getHashtags
());
$campaign
->
setHashtags
(
$campaignRef
->
getHashtags
());
return
$this
->
onCreate
(
$campaign
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/CampaignUrnDelegateSpec.php
View file @
1504e911
...
...
@@ -2,14 +2,40 @@
namespace
Spec\Minds\Core\Boost\Campaigns\Delegates
;
use
Minds\Core\Boost\Campaigns\Campaign
;
use
Minds\Core\Boost\Campaigns\CampaignException
;
use
Minds\Core\Boost\Campaigns\Delegates\CampaignUrnDelegate
;
use
Minds\Core\GuidBuilder
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
class
CampaignUrnDelegateSpec
extends
ObjectBehavior
{
/** @var GuidBuilder */
protected
$guidBuilder
;
public
function
let
(
GuidBuilder
$guidBuilder
)
{
$this
->
beConstructedWith
(
$guidBuilder
);
$this
->
guidBuilder
=
$guidBuilder
;
}
public
function
it_is_initializable
()
{
$this
->
shouldHaveType
(
CampaignUrnDelegate
::
class
);
}
public
function
it_should_throw_an_exception_if_urn_already_set
(
Campaign
$campaign
)
{
$campaign
->
getUrn
()
->
shouldBeCalled
()
->
willReturn
(
'urn:campaign:1234'
);
$this
->
shouldThrow
(
CampaignException
::
class
)
->
during
(
'onCreate'
,
[
$campaign
]);
}
public
function
it_should_create_and_set_a_urn
(
Campaign
$campaign
)
{
$campaign
->
getUrn
()
->
shouldBeCalled
()
->
willReturn
(
null
);
$this
->
guidBuilder
->
build
()
->
shouldBeCalled
()
->
willReturn
(
12345
);
$campaign
->
setUrn
(
'urn:campaign:12345'
)
->
shouldBeCalled
()
->
willReturn
(
$campaign
);
$this
->
onCreate
(
$campaign
);
}
}
This diff is collapsed.
Click to expand it.
Spec/Core/Boost/Campaigns/Delegates/NormalizeHashtagsDelegateSpec.php
View file @
1504e911
...
...
@@ -2,6 +2,8 @@
namespace
Spec\Minds\Core\Boost\Campaigns\Delegates
;
use
Minds\Core\Boost\Campaigns\Campaign
;
use
Minds\Core\Boost\Campaigns\CampaignException
;
use
Minds\Core\Boost\Campaigns\Delegates\NormalizeHashtagsDelegate
;
use
PhpSpec\ObjectBehavior
;
use
Prophecy\Argument
;
...
...
@@ -12,4 +14,84 @@ class NormalizeHashtagsDelegateSpec extends ObjectBehavior
{
$this
->
shouldHaveType
(
NormalizeHashtagsDelegate
::
class
);
}
public
function
it_should_throw_exception_if_more_than_5_hashtags_on_create
(
Campaign
$campaign
)
{
$hashtags
=
[
'one'
,
'two'
,
'three'
,
'four'
,
'five'
,
'six'
];
$campaign
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$this
->
shouldThrow
(
CampaignException
::
class
)
->
during
(
'onCreate'
,
[
$campaign
]);
}
public
function
it_should_throw_exception_if_more_than_5_hashtags_on_update
(
Campaign
$campaign
,
Campaign
$campaignRef
)
{
$hashtags
=
[
'one'
,
'two'
,
'three'
,
'four'
,
'five'
,
'six'
];
$campaignRef
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$campaign
->
setHashtags
(
$hashtags
)
->
shouldBeCalled
()
->
willReturn
(
$campaign
);
$campaign
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$this
->
shouldThrow
(
CampaignException
::
class
)
->
during
(
'onUpdate'
,
[
$campaign
,
$campaignRef
]);
}
public
function
it_should_normalise_hashtags_on_create
(
Campaign
$campaign
)
{
$hashtags
=
[
'on e'
,
'two'
,
'th*ree'
,
'four'
,
'five'
];
$hashtagsNormal
=
[
'one'
,
'two'
,
'three'
,
'four'
,
'five'
];
$campaign
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$campaign
->
setHashtags
(
$hashtagsNormal
)
->
shouldBeCalled
()
->
willReturn
(
$campaign
);
$this
->
onCreate
(
$campaign
);
}
public
function
it_should_normalise_hashtags_on_update
(
Campaign
$campaign
,
Campaign
$campaignRef
)
{
$hashtags
=
[
'on e'
,
'two'
,
'th*ree'
,
'four'
,
'five'
];
$hashtagsNormal
=
[
'one'
,
'two'
,
'three'
,
'four'
,
'five'
];
$campaignRef
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$campaign
->
setHashtags
(
$hashtags
)
->
shouldbeCalled
()
->
willReturn
(
$campaign
);
$campaign
->
getHashtags
()
->
shouldBeCalled
()
->
willReturn
(
$hashtags
);
$campaign
->
setHashtags
(
$hashtagsNormal
)
->
shouldBeCalled
()
->
willReturn
(
$campaign
);
$this
->
onUpdate
(
$campaign
,
$campaignRef
);
}
}
This diff is collapsed.
Click to expand it.