Skip to content

Commit

Permalink
Update InputFile class and it's test
Browse files Browse the repository at this point in the history
  • Loading branch information
baikunz committed Mar 25, 2013
1 parent 1c8e3d1 commit 7c3bb8b
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/Shuble/Slurpy/InputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,88 @@ class InputFile
* @var string
*/
protected $password;

/**
* Get input file path
*
* @return string
*/
public function getFilePath()
{
return $this->filePath;
}

/**
* Sets input file path
*
* @param string $filePath
*
* @return InputFile
*/
public function setFilePath($filePath)
{
$this->filePath = (string) $filePath;

return $this;
}

/**
* Get input file handle
*
* @return string
*/
public function getHandle()
{
return $this->handle;
}

/**
* Set input file handle
*
* @param string $handle
*
* @throws \InvalidArgumentException
*
* @return InputFile
*/
public function setHandle($handle)
{
if (!ctype_upper((string) $handle)) {
throw new \InvalidArgumentException(sprintf(
'"%s" is not a valid handle. A handle must be one or more upper-case letters',
$handle
));
}

$this->handle = $handle;

return $this;
}

/**
* Get input file password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}

/**
* Set Input file password
*
* @param string $password
*
* @return \Shuble\Slurpy\InputFile
*/
public function setPassword($password)
{
$this->password = null === $password
? null
: (string) $password
;

return $this;
}
}
42 changes: 42 additions & 0 deletions test/Shuble/Slurpy/InputFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Shuble\Slurpy;

use Shuble\Slurpy\PdfToolkit;

class InputFileTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider dataForGetSet
*/
public function testGetSet($property, $value)
{
$inputFile = new InputFile();

$setter = sprintf('set%s', ucfirst($property));
$getter = sprintf('get%s', ucfirst($property));

$inputFile->$setter($value);

$this->assertEquals($value, $inputFile->$getter());
}

public function dataForGetSet()
{
return array(
array('filePath', '/path/to/file'),
array('handle', 'HANDLE'),
array('password', 'pa$$w0rd'),
array('password', null),
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testSetInvalidHandle()
{
$inputFile = new InputFile();
$inputFile->setHandle('foo');
}
}

0 comments on commit 7c3bb8b

Please sign in to comment.