-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #837 from PROCERGS/preview-1.21.1
v1.21.1
- Loading branch information
Showing
4 changed files
with
112 additions
and
8 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/LoginCidadao/BadgesControlBundle/Tests/BadgeMocker.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\BadgesControlBundle\Tests; | ||
|
||
use LoginCidadao\BadgesControlBundle\Model\BadgeInterface; | ||
|
||
class BadgeMocker | ||
{ | ||
public static function getBadge($namespace, $name): BadgeInterface | ||
{ | ||
return new class($namespace, $name) implements BadgeInterface | ||
{ | ||
private $namespace; | ||
private $name; | ||
|
||
public function __construct(string $namespace, string $name) | ||
{ | ||
$this->namespace = $namespace; | ||
$this->name = $name; | ||
} | ||
|
||
public function getNamespace() | ||
{ | ||
return $this->namespace; | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getData() | ||
{ | ||
return true; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return "{$this->getNamespace()}.{$this->getName()}"; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* This file is part of the login-cidadao project or it's bundles. | ||
* | ||
* (c) Guilherme Donato <guilhermednt on github> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace LoginCidadao\CoreBundle\Tests\Entity; | ||
|
||
use LoginCidadao\BadgesControlBundle\Tests\BadgeMocker; | ||
use LoginCidadao\CoreBundle\Entity\Person; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PersonTest extends TestCase | ||
{ | ||
public function testBadges() | ||
{ | ||
$badge1 = BadgeMocker::getBadge('namespace1', 'badge1'); | ||
$badge2 = BadgeMocker::getBadge('namespace1', 'badge2'); | ||
$badge3 = BadgeMocker::getBadge('namespace2', 'badge1'); | ||
|
||
$person = new Person(); | ||
$person->mergeBadges([$badge1]); | ||
$person->mergeBadges([$badge2, $badge3]); | ||
|
||
$badges = $person->getBadges(); | ||
|
||
$this->assertCount(3, $badges); | ||
$this->assertContains('namespace1.badge1', array_keys($badges)); | ||
$this->assertContains('namespace1.badge2', array_keys($badges)); | ||
$this->assertContains('namespace2.badge1', array_keys($badges)); | ||
|
||
$this->assertSame($badge1, $badges['namespace1.badge1']); | ||
$this->assertSame($badge2, $badges['namespace1.badge2']); | ||
$this->assertSame($badge3, $badges['namespace2.badge1']); | ||
} | ||
|
||
public function testEmptyBadges() | ||
{ | ||
$person = new Person(); | ||
|
||
$this->assertEmpty($person->getBadges()); | ||
} | ||
} |