/** * Builds an instance of a serializer if the internal instance is null * @param int $dataFormat * @param int $maxDepth * @param string $configurationPath * @return Serializer * @throws \LogicException * @throws ParseException */ public static function getSerializer($dataFormat = IsSerializable::FORMAT_JSON, $maxDepth = IsSerializable::MAX_DEPTH_NOT_SET, $configurationPath = './config') { if (null === self::$serializerInstance) { switch ($dataFormat) { case IsSerializable::FORMAT_JSON: $instance = new JSONSerializer($maxDepth, $configurationPath); break; default: throw new \LogicException('An unsupported serializer type was requested'); } self::$serializerInstance = $instance; self::$serializerInstance->loadConfiguration(); } return self::$serializerInstance; }
public function testIncrementDecrementCurrentDepth() { $maxDepth = 3; $this->instance->setDepth($maxDepth); $this->assertEquals($maxDepth, $this->instance->getDepth()); $this->assertEquals(1, $this->instance->getCurrentDepth()); $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); $this->assertTrue($this->instance->isWithinBounds()); $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); $this->assertEquals($maxDepth, $this->instance->getCurrentDepth()); $this->assertTrue($this->instance->isWithinBounds()); $this->assertTrue($this->instance->incrementCurrentDepth() instanceof Serializer); $this->assertFalse($this->instance->isWithinBounds()); $this->assertTrue($this->instance->decrementCurrentDepth() instanceof Serializer); $this->assertTrue($this->instance->isWithinBounds()); $this->instance->resetCurrentDepth(); $this->assertNotEquals($maxDepth, $this->instance->getCurrentDepth()); }