public function testCanBeString() { $result = can_be_valid_string(null); $this->assertEquals(false, $result); $result = can_be_valid_string(new ObjectWithToStringTestClass()); $this->assertEquals(true, $result); $result = can_be_valid_string(new ObjectWithoutToStringTestClass()); $this->assertEquals(false, $result); $result = can_be_valid_string($this->testArray); $this->assertEquals(false, $result); $result = can_be_valid_string($this->testArray, true); $this->assertEquals(true, $result); $result = can_be_valid_string('This is a string'); $this->assertEquals(true, $result); $result = can_be_valid_string(1); $this->assertEquals(true, $result); $result = can_be_valid_string(1.1); $this->assertEquals(true, $result); $result = can_be_valid_string(0x1a); $this->assertEquals(true, $result); $result = can_be_valid_string(false); $this->assertEquals(true, $result); }
/** * Sets an attributes value by name. * * @param string $attributeName * @param string $attributeValue */ public function setAttribute($attributeName, $attributeValue) { if (can_be_valid_string($attributeValue, true)) { $this->attributes[$attributeName] = $attributeValue; } }
/** * Sets the active route path. * * @param string $routePath * @return void */ public function setRoutePath($routePath) { if (can_be_valid_string($routePath)) { $this->activeRoutePath = (string) $routePath; } else { throw new InvalidArgumentException("The route path '{$routePath}' is not a valid string."); } }