/** * (non-PHPdoc) * * @see \Solvire\API\Serializers\DataFields\DataField::setData() */ public function setData($data) { if (!is_string($data)) { throw new \RuntimeException('GenderField data must be a valid representation of a normalized gender : ' . $data . ' in ' . $this->name); } $gender = G::spot($data); if ($gender === 'male') { $this->data = $this->maleValue; } elseif ($gender === 'female') { $this->data = $this->femaleValue; } return $this; }
/** */ public function testCanBeNormalize() { $g = G::spot('man'); $this->assertEquals('male', $g); $this->assertEquals('male', G::getMaleValue()); G::setMaleValue('pig'); $this->assertNotEquals('male', G::getMaleValue()); $g = G::spot('woman'); $this->assertEquals('female', $g); G::setFemaleValue('BADASS'); $this->assertNotEquals('female', G::getFemaleValue()); try { G::spot('dolphin'); } catch (\Solvire\Utilities\GenderDivisibilityException $e) { $this->assertInstanceOf('\\Solvire\\Utilities\\GenderDivisibilityException', $e); } // not a trans am $trans = G::spot('trans man', false); $this->assertEquals('trans man', $trans); $wat = G::spot('dolphin', false); $this->assertEquals('other', $wat); }