Skip to content

Commit

Permalink
add __toString function on attributes fix #13
Browse files Browse the repository at this point in the history
  • Loading branch information
mhor committed Jan 24, 2015
1 parent 297820d commit be45a99
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Attribute/AttributeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@

interface AttributeInterface
{
/**
* @return string
*/
public function __toString();
}
8 changes: 8 additions & 0 deletions src/Attribute/Cover.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,12 @@ public function getBinaryCover()
{
return $this->binaryCover;
}

/**
* @return string
*/
public function __toString()
{
return $this->binaryCover;
}
}
8 changes: 8 additions & 0 deletions src/Attribute/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public function getMilliseconds()
{
return $this->milliseconds;
}

/**
* @return string
*/
public function __toString()
{
return (string) $this->milliseconds;
}
}
8 changes: 8 additions & 0 deletions src/Attribute/Mode.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public function getShortName()
{
return $this->shortName;
}

/**
* @return string
*/
public function __toString()
{
return $this->shortName;
}
}
8 changes: 8 additions & 0 deletions src/Attribute/Rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public function getTextValue()
{
return $this->textValue;
}

/**
* @return string
*/
public function __toString()
{
return $this->textValue;
}
}
8 changes: 8 additions & 0 deletions src/Attribute/Size.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ public function getBit()
{
return $this->bit;
}

/**
* @return string
*/
public function __toString()
{
return (string) $this->bit;
}
}
5 changes: 5 additions & 0 deletions test/Attribute/AttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,36 @@ public function testCover()
{
$cover = new Cover('binary_string');
$this->assertEquals('binary_string', $cover->getBinaryCover());
$this->assertSame('binary_string', (string)$cover);
}

public function testDuration()
{
$duration = new Duration(1000);
$this->assertEquals(1000, $duration->getMilliseconds());
$this->assertSame('1000', (string)$duration);
}

public function testMode()
{
$mode = new Mode('short', 'full');
$this->assertEquals('short', $mode->getShortName());
$this->assertEquals('full', $mode->getFullName());
$this->assertSame('short', (string)$mode);
}

public function testRate()
{
$rate = new Rate(15555, '15.55 Mo');
$this->assertEquals(15555, $rate->getAbsoluteValue());
$this->assertEquals('15.55 Mo', $rate->getTextValue());
$this->assertSame('15.55 Mo', (string)$rate);
}

public function testSize()
{
$size = new Size(42);
$this->assertEquals(42, $size->getBit());
$this->assertSame('42', (string)$size);
}
}

0 comments on commit be45a99

Please sign in to comment.