-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
264 additions
and
37 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
[![License](https://poser.pugx.org/guillegf/secret-santa/license)](https://packagist.org/packages/guillegf/secret-santa) | ||
|
||
* Repository: https://github.com/GuilleGF/SecretSantaPHP | ||
* Version: 1.1.1 | ||
* Version: 1.2.0 | ||
* License: MIT, see [LICENSE](LICENSE) | ||
|
||
## Description | ||
|
@@ -31,29 +31,53 @@ documentation. | |
To add this dependency using the command, run the following from within your | ||
project directory: | ||
``` | ||
composer require guillegf/secret-santa "~1.1" | ||
composer require guillegf/secret-santa "~1.2" | ||
``` | ||
|
||
Alternatively, add the dependency directly to your `composer.json` file: | ||
```json | ||
"require": { | ||
"guillegf/secret-santa": "~1.1" | ||
"guillegf/secret-santa": "~1.2" | ||
} | ||
``` | ||
## Usage | ||
|
||
In this example in total we add 10 players, 2 singles players, 2 couples (exclusive) and 4 exclusive players. | ||
|
||
**The couples and exclusive players never match together.** | ||
|
||
```php | ||
<?php | ||
$secretSanta = new SecretSanta(); | ||
$secretSanta->addPlayer('Player', 'player@email.com') | ||
$secretSanta->addPlayer('Player1', 'player1@email.com') | ||
->addPlayer('Player2', '[email protected]') | ||
->addCouple('Player3', '[email protected]', 'Couple3', '[email protected]') | ||
->addCouple('Player4', '[email protected]', 'Couple4', '[email protected]'); | ||
->addCouple('Player4', '[email protected]', 'Couple4', '[email protected]') | ||
->addExclusivePlayers( | ||
['Player5', '[email protected]'], | ||
['Player6', '[email protected]'], | ||
['Player7', '[email protected]'], | ||
['Player8', '[email protected]'] | ||
); | ||
|
||
foreach ($secretSanta->play() as $player) { | ||
echo ("{$player->name()} ({$player->email()}): {$player->secretSanta()->name()}\n"); | ||
} | ||
``` | ||
The above example will output: | ||
|
||
```php | ||
Player1 ([email protected]): Player5 | ||
Player2 ([email protected]): Player7 | ||
Player3 ([email protected]): Player2 | ||
Couple3 ([email protected]): Player8 | ||
Player4 ([email protected]): Player3 | ||
Couple4 ([email protected]): Player6 | ||
Player5 ([email protected]): Player4 | ||
Player6 ([email protected]): Player1 | ||
Player7 ([email protected]): Couple3 | ||
Player8 ([email protected]): Couple4 | ||
``` | ||
|
||
## License | ||
|
||
|
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
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 |
---|---|---|
|
@@ -96,7 +96,7 @@ public function testShufflePlayers() | |
$this->assertNotEquals(array_keys($playersCollection->players()), array_keys($shufflePlayers)); | ||
} | ||
|
||
public function testExcludePlayers() | ||
public function testExclusivePlayers() | ||
{ | ||
$expectedSinglePlayer = Player::create('nameSingle', '[email protected]'); | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
|
@@ -105,8 +105,59 @@ public function testExcludePlayers() | |
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addCouple($expectedPlayer, $expectedCouple); | ||
|
||
$this->assertTrue($playersCollection->areExclude($expectedPlayer, $expectedCouple)); | ||
$this->assertFalse($playersCollection->areExclude($expectedSinglePlayer, $expectedPlayer)); | ||
$this->assertSame(2, $playersCollection->countExcludePlayers()); | ||
$this->assertTrue($playersCollection->areExclusive($expectedPlayer, $expectedCouple)); | ||
$this->assertFalse($playersCollection->areExclusive($expectedSinglePlayer, $expectedPlayer)); | ||
$this->assertSame(2, $playersCollection->countExclusivePlayers()); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayersCollectionException | ||
*/ | ||
public function AddExclusivePlayersEmpty() | ||
{ | ||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addExclusivePlayers([]); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayersCollectionException | ||
*/ | ||
public function AddExclusivePlayersOnlyOnePlayer() | ||
{ | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
|
||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addExclusivePlayers( | ||
[$expectedPlayer] | ||
); | ||
} | ||
|
||
/** | ||
* @expectedException \SecretSanta\Exceptions\PlayersCollectionException | ||
*/ | ||
public function AddExclusivePlayersOnlyTwoPlayer() | ||
{ | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
$expectedPlayer2 = Player::create('name2', '[email protected]'); | ||
|
||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addExclusivePlayers([ | ||
$expectedPlayer, | ||
$expectedPlayer2 | ||
]); | ||
} | ||
|
||
public function AddExclusivePlayersThreePlayer() | ||
{ | ||
$expectedPlayer = Player::create('name', '[email protected]'); | ||
$expectedPlayer2 = Player::create('name2', '[email protected]'); | ||
$expectedPlayer3 = Player::create('name3', '[email protected]'); | ||
|
||
$playersCollection = new PlayersCollection(); | ||
$playersCollection->addExclusivePlayers([ | ||
$expectedPlayer, | ||
$expectedPlayer2, | ||
$expectedPlayer3 | ||
]); | ||
} | ||
} |
Oops, something went wrong.