Example #1
0
 /**
  * Test for `Field::setRealType()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Field::__construct
  * @requires function Freyja\Database\Schema\Field::double
  * @requires function Freyja\Database\Schema\Field::setRealType
  * @requires function ReflectionProperty::setAccessible
  * @requires function ReflectionProperty::getValue
  */
 public function testSetRealType()
 {
     // Set accessibility to object properties.
     $reflection_length = new ReflectionProperty('Freyja\\Database\\Schema\\Field', 'length');
     $reflection_decimals = new ReflectionProperty('Freyja\\Database\\Schema\\Field', 'decimals');
     $reflection_length->setAccessible(true);
     $reflection_decimals->setAccessible(true);
     $field = new Field('name');
     $field->double(300, 28);
     $retrieved_length_1 = $reflection_length->getValue($field);
     $retrieved_decimals_1 = $reflection_decimals->getValue($field);
     $this->assertEquals(29, $retrieved_length_1, 'Failed asserting that Field::setRealType() correctly set length to 1 unit more than decimals, if decimals is valid, and length isn\'t.');
     $this->assertEquals(28, $retrieved_decimals_1, 'Failed asserting that Field::setRealType() correctly set decimals if it\'s valid, when length is invalid.');
     $field = new Field('name');
     $field->double(300, 8);
     $retrieved_length_2 = $reflection_length->getValue($field);
     $retrieved_decimals_2 = $reflection_decimals->getValue($field);
     $this->assertEquals(16, $retrieved_length_2, 'Failed asserting that Field::setRealType() correctly set length to default if decimals is valid and minor than default length, and length isn\'t valid.');
     $this->assertEquals(8, $retrieved_decimals_2, 'Failed asserting that Field::setRealType() correctly set decimals if it\'s valid and minor than default length, when length is invalid.');
     $field = new Field('name');
     $field->double(17, 35);
     $retrieved_length_3 = $reflection_length->getValue($field);
     $retrieved_decimals_3 = $reflection_decimals->getValue($field);
     $this->assertEquals(17, $retrieved_length_3, 'Failed asserting that Field::setRealType() correctly set length if it\'s greater than default decimals, if decimals is invalid.');
     $this->assertEquals(4, $retrieved_decimals_3, 'Failed asserting that Field::setRealType() correctly set decimals to default, if it\'s invalid when length is valid and greater than default decimals.');
     $field = new Field('name');
     $field->double(2, 35);
     $retrieved_length_4 = $reflection_length->getValue($field);
     $retrieved_decimals_4 = $reflection_decimals->getValue($field);
     $this->assertEquals(16, $retrieved_length_4, 'Failed asserting that Field::setRealType() correctly set length to default, if decimals is invalid, and length is lower than default decimals.');
     $this->assertEquals(4, $retrieved_decimals_4, 'Failed asserting that Field::setRealType() correctly set decimals to default if invalid, when length is valid, but lower than decimals default.');
     $field = new Field('name');
     $field->double(12, 12);
     $retrieved_length_5 = $reflection_length->getValue($field);
     $retrieved_decimals_5 = $reflection_decimals->getValue($field);
     $this->assertEquals(16, $retrieved_length_5, 'Failed asserting that Field::setRealType() correctly set length to default, if it\'s equal to decimals, and decimals is valid and lower than default length.');
     $this->assertEquals(12, $retrieved_decimals_5, 'Failed asserting that Field::setRealType() correctly set decimals when equal to length, and lower than default length.');
     $field = new Field('name');
     $field->double(20, 20);
     $retrieved_length_6 = $reflection_length->getValue($field);
     $retrieved_decimals_6 = $reflection_decimals->getValue($field);
     $this->assertEquals(21, $retrieved_length_6, 'Failed asserting that Field::setRealType() correctly set length to 1 unit more than decimals, if equal to decimals, but decimals is greater than default length.');
     $this->assertEquals(20, $retrieved_decimals_6, 'Failed asserting that Field::setRealType() correctly set decimals when equal to length, and greater than default length.');
 }