Skip to content

Commit

Permalink
Add test for Subject
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePastore committed Nov 22, 2015
1 parent 0571380 commit 5b0fa8b
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/DavidePastore/CodiceFiscale/Calculator.php
Expand Up @@ -187,11 +187,11 @@ public function calculateAllPossibilities()
*/
private function calculateSurname()
{
$consonants = str_replace($this->vowels, '', $this->subject->getSurname());
$consonants = str_replace($this->vowels, '', strtoupper($this->subject->getSurname()));
if (strlen($consonants) > 2) {
$result = substr($consonants, 0, 3);
} else {
$vowels = str_replace(str_split($consonants), '', $this->subject->getSurname());
$vowels = str_replace(str_split($consonants), '', strtoupper($this->subject->getSurname()));
$result = substr($consonants.$vowels.'XXX', 0, 3);
}

Expand All @@ -205,13 +205,13 @@ private function calculateSurname()
*/
private function calculateName()
{
$consonants = str_replace($this->vowels, '', $this->subject->getName());
$consonants = str_replace($this->vowels, '', strtoupper($this->subject->getName()));
if (strlen($consonants) > 3) {
$result = $consonants[0].$consonants[2].$consonants[3];
} elseif (strlen($consonants) == 3) {
$result = implode($consonants);
} else {
$vowels = str_replace(str_split($consonants), '', $this->subject->getName());
$vowels = str_replace(str_split($consonants), '', strtoupper($this->subject->getName()));
$result = substr($consonants.$vowels.'XXX', 0, 3);
}

Expand All @@ -228,7 +228,7 @@ private function calculateBirthDateAndGender()
$year = $this->subject->getBirthDate()->format('y');
$month = $this->months[$this->subject->getBirthDate()->format('n')];
$day = $this->subject->getBirthDate()->format('d');
if ($this->subject->getGender() == 'F') {
if (strtoupper($this->subject->getGender()) == 'F') {
$day += 40;
}

Expand All @@ -242,7 +242,7 @@ private function calculateBirthDateAndGender()
*/
private function calculateBelfioreCode()
{
return $this->subject->getBelfioreCode();
return strtoupper($this->subject->getBelfioreCode());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/DavidePastore/CodiceFiscale/Subject.php
Expand Up @@ -30,11 +30,11 @@ public function __construct($properties)
{
//Set properties
if (array_key_exists('name', $properties)) {
$this->name = strtoupper($properties['name']);
$this->name = $properties['name'];
}

if (array_key_exists('surname', $properties)) {
$this->surname = strtoupper($properties['surname']);
$this->surname = $properties['surname'];
}

if (array_key_exists('birthDate', $properties)) {
Expand All @@ -45,7 +45,7 @@ public function __construct($properties)
}

if (array_key_exists('gender', $properties)) {
$this->gender = strtoupper($properties['gender']);
$this->gender = $properties['gender'];
}

if (array_key_exists('belfioreCode', $properties)) {
Expand Down
206 changes: 206 additions & 0 deletions test/DavidePastore/CodiceFiscale/SubjectTest.php
@@ -0,0 +1,206 @@
<?php

namespace DavidePastore\CodiceFiscale;

/**
* Test for the Checker class.
*
* @author davidepastore
*/
class SubjectTest extends \PHPUnit_Framework_TestCase
{
/**
* Test for getName.
*/
public function testGetName()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$actual = $subject->getName();
$expected = 'Mario';
$this->assertEquals($expected, $actual);
}

/**
* Test for setName.
*/
public function testSetName()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$subject->setName('Fabrizio');
$actual = $subject->getName();
$expected = 'Fabrizio';
$this->assertEquals($expected, $actual);
}

/**
* Test for getSurname.
*/
public function testGetSurname()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$actual = $subject->getSurname();
$expected = 'Rossi';
$this->assertEquals($expected, $actual);
}

/**
* Test for setSurname.
*/
public function testSetSurname()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$subject->setSurname('Russo');
$actual = $subject->getSurname();
$expected = 'Russo';
$this->assertEquals($expected, $actual);
}

/**
* Test for getBirthDate.
*/
public function testGetBirthDate()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$actual = $subject->getBirthDate();
$expected = new \DateTime('1985-12-10');
$this->assertEquals($expected, $actual);
}

/**
* Test for setBirthDate.
*/
public function testSetBirthDate()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$subject->setBirthDate(new \DateTime('1944-01-10'));
$actual = $subject->getBirthDate();
$expected = new \DateTime('1944-01-10');
$this->assertEquals($expected, $actual);
}

/**
* Test for getGender.
*/
public function testGetGender()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$actual = $subject->getGender();
$expected = 'M';
$this->assertEquals($expected, $actual);
}

/**
* Test for setGender.
*/
public function testSetGender()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$subject->setGender('F');
$actual = $subject->getGender();
$expected = 'F';
$this->assertEquals($expected, $actual);
}

/**
* Test for getBelfioreCode.
*/
public function testGetBelfioreCode()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$actual = $subject->getBelfioreCode();
$expected = 'A562';
$this->assertEquals($expected, $actual);
}

/**
* Test for setGender.
*/
public function testSetBelfioreCode()
{
$subject = new Subject(
array(
'name' => 'Mario',
'surname' => 'Rossi',
'birthDate' => '1985-12-10',
'gender' => 'M',
'belfioreCode' => 'A562',
)
);
$subject->setBelfioreCode('H501');
$actual = $subject->getBelfioreCode();
$expected = 'H501';
$this->assertEquals($expected, $actual);
}
}

0 comments on commit 5b0fa8b

Please sign in to comment.