Skip to content

Commit

Permalink
Merge pull request #3 from chadicus/fea/immutable-keyvaluepair
Browse files Browse the repository at this point in the history
Replace KeyValuePair with ImmutableKeyValuePair
  • Loading branch information
chadicus committed Sep 14, 2015
2 parents 9b3d785 + 8695d16 commit 57a578b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 102 deletions.
28 changes: 1 addition & 27 deletions src/KeyValuePair.php → src/ImmutableKeyValuePair.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**
* Defines an immutable key/value pair.
*/
class KeyValuePair
final class ImmutableKeyValuePair implements KeyValuePairInterface
{
/**
* The key in the key/value pair.
Expand Down Expand Up @@ -51,30 +51,4 @@ public function getValue()
{
return $this->value;
}

/**
* Sets the key in the key/value pair.
*
* @param mixed $key The new key.
*
* @return KeyValuePair
*/
public function setKey($key)
{
$this->key = $key;
return $this;
}

/**
* Sets the value in the key/value pair.
*
* @param mixed $value The new value.
*
* @return mixed
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
}
22 changes: 22 additions & 0 deletions src/KeyValuePairInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Chadicus\Spl\DataStructures;

/**
* Defines a key/value pair interface.
*/
interface KeyValuePairInterface
{
/**
* Gets the key in the key/value pair.
*
* @return mixed
*/
public function getKey();

/**
* Gets the value in the key/value pair.
*
* @return mixed
*/
public function getValue();
}
31 changes: 31 additions & 0 deletions tests/ImmutableKeyValuePairTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
namespace ChadicusTest\Spl\DataStructures;

use Chadicus\Spl\DataStructures\ImmutableKeyValuePair;

/**
* Unit tests for the \Chadicus\Spl\DataStructures\ImmutableKeyValuePair class.
*
* @coversDefaultClass \Chadicus\Spl\DataStructures\ImmutableKeyValuePair
*/
final class ImmutableKeyValuePairTest extends \PHPUnit_Framework_TestCase
{
/**
* Verify basic behavior of ImmutableKeyValuePair class.
*
* @test
* @covers ::__construct
* @covers ::getValue
* @covers ::getKey
*
* @return void
*/
public function basicUsage()
{
$key = new \StdClass();
$value = new \Exception();
$pair = new ImmutableKeyValuePair($key, $value);
$this->assertSame($key, $pair->getKey());
$this->assertSame($value, $pair->getValue());
}
}
75 changes: 0 additions & 75 deletions tests/KeyValuePairTest.php

This file was deleted.

0 comments on commit 57a578b

Please sign in to comment.