-
| STRING (1) | BINARY (2) | LONG (3) | DOUBLE (4) | DATE (5) | BOOLEAN (6) | NAME(7) | PATH (8) | REFERENCE (9/10) | URI (11) | DECIMAL (12) |
- | STRING | x | Utf-8 encoded | cast to int | cast to float | SYYYY-MM-DDThh:Mm:ss.sssTZD | '' is false, else true | if valid name, name | if valid path, as name | check valid uuid | RFC 3986 | string |
- | BINARY | Utf-8 | x | Converted to string and then interpreted as above |
- | LONG | cast to string | String, then Utf-8 | x | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
- | DOUBLE | cast to string | String, then Utf-8 | cast to int | x | Unix Time | 0.0 is false, else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
- | DATE | SYYYY-MM-DDThh: Mm:ss.sssTZD | String, then Utf-8 | Unix timestamp | Unix timestamp | x |
- true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | Unix timestamp |
- | BOOLEAN | cast to string | String, then Utf-8 | 0/1 | 0.0/1.0 | ValueFormatException | x | '0'/'1' |
- ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException |
- | NAME | Qualified form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | noop (relative path) | ValueFormatException | „./“ and qualified name. % encode illegal characters | ValueFormatException |
- | PATH | Standard form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | if relative path lenght 1 noop / otherwise ValueFormatException | x | ValueFormatException | „./“ if not starting with /. % encode illegal characters | ValueFormatException |
- | REFERENCE | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | ValueFormatException | ValueFormatException |
- | URI | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException |
- ValueFormatException | single name: decode %, remove ./ else ValueFormatException | Decode %, remove leading ./ . if not star w. name, / or ./ then ValueFormatException | ValueFormatException | x | ValueFormatException |
- | DECIMAL | noop | Utf-8 encoded | cast to int | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x |
-
+ *
+ *
| STRING (1) | BINARY (2) | LONG (3) | DOUBLE (4) | DATE (5) | BOOLEAN (6) | NAME(7) | PATH (8) | REFERENCE (9/10) | URI (11) | DECIMAL (12) |
+ * | STRING | x | Utf-8 encoded | cast to int | cast to float | SYYYY-MM-DDThh:Mm:ss.sssTZD | '' is false, else true | if valid name, name | if valid path, as name | check valid uuid | RFC 3986 | string |
+ * | BINARY | Utf-8 | x | Converted to string and then interpreted as above |
+ * | LONG | cast to string | String, then Utf-8 | x | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
+ * | DOUBLE | cast to string | String, then Utf-8 | cast to int | x | Unix Time | 0.0 is false, else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | cast to string |
+ * | DATE | SYYYY-MM-DDThh: Mm:ss.sssTZD | String, then Utf-8 | Unix timestamp | Unix timestamp | x |
+ * true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | Unix timestamp |
+ * | BOOLEAN | cast to string | String, then Utf-8 | 0/1 | 0.0/1.0 | ValueFormatException | x | '0'/'1' |
+ * ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException |
+ * | NAME | Qualified form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | noop (relative path) | ValueFormatException | „./“ and qualified name. % encode illegal characters | ValueFormatException |
+ * | PATH | Standard form | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | if relative path lenght 1 noop / otherwise ValueFormatException | x | ValueFormatException | „./“ if not starting with /. % encode illegal characters | ValueFormatException |
+ * | REFERENCE | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x | ValueFormatException | ValueFormatException |
+ * | URI | noop | String, then Utf-8 | ValueFormatException | ValueFormatException | ValueFormatException |
+ * ValueFormatException | single name: decode %, remove ./ else ValueFormatException | Decode %, remove leading ./ . if not star w. name, / or ./ then ValueFormatException | ValueFormatException | x | ValueFormatException |
+ * | DECIMAL | noop | Utf-8 encoded | cast to int | cast to float | Unix Time | 0 false else true | ValueFormatException | ValueFormatException | ValueFormatException | ValueFormatException | x |
+ *
*
* @param mixed $value The value or value array to check and convert
* @param int $type Target type to convert into. One of the type constants in PropertyType
- * @param int $srctype Source type to convert from, if not specified this is automatically determined, which will miss the string based types that are not strings (DECIMAL, NAME, PATH, URI)
+ * @param int $srcType Source type to convert from, if not specified this is automatically determined, which will miss the string based types that are not strings (DECIMAL, NAME, PATH, URI)
*
* @return mixed the value casted into the proper format (throws an exception if conversion is not possible)
*
- * @throws ValueFormatException is thrown if the specified value cannot be converted to the specified type
- * @throws RepositoryException if the specified Node is not referenceable, the current Session is no longer active, or another error occurs.
+ * @throws RepositoryException if the specified Node is not referenceable, the current Session is no longer active, or another error occurs
* @throws \InvalidArgumentException if the specified DateTime value cannot be expressed in the ISO 8601-based format defined in the JCR 2.0 specification and the implementation does not support dates incompatible with that format.
+ * @throws ValueFormatException is thrown if the specified value cannot be converted to the specified type
*
* @see http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.6.4%20Property%20Type%20Conversion
*/
- public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
+ public function convertType(mixed $value, int $type, int $srcType = PropertyType::UNDEFINED): mixed
{
if (is_array($value)) {
- $ret = array();
+ $ret = [];
foreach ($value as $v) {
- $ret[] = self::convertType($v, $type, $srctype);
+ $ret[] = self::convertType($v, $type, $srcType);
}
return $ret;
}
- if (PropertyType::UNDEFINED == $srctype) {
- $srctype = $this->determineType($value);
+ if (PropertyType::UNDEFINED === $srcType) {
+ $srcType = $this->determineType($value);
}
if ($value instanceof PropertyInterface) {
@@ -121,61 +136,58 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
}
// except on noop, stream needs to be read into string first
- if (PropertyType::BINARY == $srctype && PropertyType::BINARY != $type && is_resource($value)) {
+ if (PropertyType::BINARY === $srcType && PropertyType::BINARY !== $type && is_resource($value)) {
$t = stream_get_contents($value);
rewind($value);
$value = $t;
- $srctype = PropertyType::STRING;
- } elseif ((PropertyType::REFERENCE == $srctype || PropertyType::WEAKREFERENCE == $srctype )
+ $srcType = PropertyType::STRING;
+ } elseif ((PropertyType::REFERENCE === $srcType || PropertyType::WEAKREFERENCE === $srcType)
&& $value instanceof NodeInterface
) {
- /** @var $value NodeInterface */
- // In Jackrabbit a new node cannot be referenced until it has been persisted
- // See: https://issues.apache.org/jira/browse/JCR-1614
- if ($value->isNew()) {
- throw new ValueFormatException('Node ' . $value->getPath() . ' must be persisted before being referenceable');
- }
- if (! $value->isNodeType('mix:referenceable')) {
- throw new ValueFormatException('Node ' . $value->getPath() . ' is not referenceable');
+ if (!$value->isNodeType('mix:referenceable')) {
+ throw new ValueFormatException('Node '.$value->getPath().' is not referenceable');
}
$value = $value->getIdentifier();
}
switch ($type) {
case PropertyType::STRING:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::DATE:
- if (! $value instanceof \DateTime) {
- throw new RepositoryException('Can not convert a date that is not a \DateTime instance to string');
+ if (!$value instanceof \DateTime) {
+ throw new RepositoryException('Cannot convert a date that is not a \DateTime instance to string');
}
- /** @var $value \DateTime */
+
+ /* @var $value DateTime */
// Milliseconds formatting is not possible in PHP so we
// construct it by cutting microseconds to 3 positions.
// This might not be as accurate as "real" rounded milliseconds.
- return $value->format('Y-m-d\TH:i:s.') .
- substr($value->format('u'), 0, 3) .
+ return $value->format('Y-m-d\TH:i:s.').
+ substr($value->format('u'), 0, 3).
$value->format('P');
case PropertyType::NAME:
case PropertyType::PATH:
// TODO: The name/path is converted to qualified form according to the current local namespace mapping (see §3.2.5.2 Qualified Form).
- return $value;
+ return $value;
default:
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to STRING');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to STRING');
}
if (is_resource($value)) {
throw new ValueFormatException('Inconsistency: Non-binary property should not have resource stream value');
}
+
// TODO: how can we provide ValueFormatException on failure? invalid casting leads to 'catchable fatal error' instead of exception
return (string) $value;
}
+ // no break
case PropertyType::BINARY:
if (is_resource($value)) {
return $value;
}
- if (! is_string($value)) {
- $value = $this->convertType($value, PropertyType::STRING, $srctype);
+ if (!is_string($value)) {
+ $value = $this->convertType($value, PropertyType::STRING, $srcType);
}
$f = fopen('php://memory', 'rwb+');
fwrite($f, $value);
@@ -184,94 +196,106 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
return $f;
case PropertyType::LONG:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::LONG:
case PropertyType::DOUBLE:
case PropertyType::BOOLEAN:
case PropertyType::DECIMAL:
- return (integer) $value;
+ return (int) $value;
case PropertyType::DATE:
- if (! $value instanceof \DateTime) {
+ if (!$value instanceof \DateTime) {
throw new RepositoryException('something weird');
}
- /** @var $value \DateTime */
+ /* @var $value DateTime */
return $value->getTimestamp();
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a LONG');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a LONG');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to a LONG');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to a LONG');
case PropertyType::DOUBLE:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::LONG:
case PropertyType::DOUBLE:
case PropertyType::BOOLEAN:
case PropertyType::DECIMAL:
- return (double) $value;
+ return (float) $value;
case PropertyType::DATE:
- if (! $value instanceof \DateTime) {
+ if (!$value instanceof \DateTime) {
throw new RepositoryException('something weird');
}
- /** @var $value \DateTime */
+ /* @var $value DateTime */
- return (double) $value->getTimestamp();
+ return (float) $value->getTimestamp();
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a DOUBLE');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a DOUBLE');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to a DOUBLE');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to a DOUBLE');
case PropertyType::DATE:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::DATE:
if ($value instanceof \DateTime) {
return $value;
}
+
try {
return new \DateTime($value);
} catch (\Exception $e) {
- throw new ValueFormatException("String '$value' is not a valid date", null, $e);
+ throw new ValueFormatException("String '$value' is not a valid date", 0, $e);
}
case PropertyType::LONG:
+ return (new \DateTime())
+ ->setTimestamp($value)
+ ;
case PropertyType::DOUBLE:
+ return (new \DateTime())
+ ->setTimestamp((int) round($value))
+ ;
case PropertyType::DECIMAL:
- $datetime = new \DateTime();
- $datetime = $datetime->setTimestamp($value);
+ if (function_exists('bccomp')
+ && 1 === \bccomp($value, (string) PHP_INT_MAX)
+ ) {
+ throw new ValueFormatException('Decimal number is too large for integer');
+ }
- return $datetime;
+ return (new \DateTime())
+ ->setTimestamp((int) round((float) $value))
+ ;
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a DATE');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a DATE');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to DATE');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to DATE');
case PropertyType::BOOLEAN:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::LONG:
case PropertyType::DOUBLE:
case PropertyType::BOOLEAN:
- return (boolean) $value;
+ return (bool) $value;
case PropertyType::DATE:
- /** @var $value \DateTime */
+ /* @var $value DateTime */
- return (boolean) $value->getTimestamp();
+ return (bool) $value->getTimestamp();
case PropertyType::DECIMAL:
- return (boolean) ((double) $value); // '0' is false too
+ return (bool) ((float) $value); // '0' is false too
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a BOOLEAN');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a BOOLEAN');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to a BOOLEAN');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to a BOOLEAN');
case PropertyType::NAME:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::PATH:
case PropertyType::NAME:
@@ -282,12 +306,12 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
return $value;
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a NAME');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a NAME');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to NAME');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to NAME');
case PropertyType::PATH:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
// TODO: check if valid
return $value;
@@ -299,39 +323,39 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
return $value;
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a PATH');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a PATH');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to PATH');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to PATH');
case PropertyType::REFERENCE:
case PropertyType::WEAKREFERENCE:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
case PropertyType::REFERENCE:
case PropertyType::WEAKREFERENCE:
if (empty($value)) {
- //TODO check if string is valid uuid
- throw new ValueFormatException('Value '.var_export($value, true).' is not a valid unique id');
+ // TODO check if string is valid uuid
+ throw new ValueFormatException('Value "'.var_export($value, true).'" is not a valid unique id');
}
return $value;
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a unique id');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a unique id');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to unique id');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to unique id');
case PropertyType::URI:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
// TODO: check if valid
return $value;
case PropertyType::NAME:
return '../'.rawurlencode($value);
case PropertyType::PATH:
- if (strlen($value) > 0
- && '/' != $value[0]
- && '.' != $value[0]
+ if ('' !== $value
+ && '/' !== $value[0]
+ && '.' !== $value[0]
) {
$value = './'.$value;
}
@@ -341,12 +365,12 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
return $value;
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a URI');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a URI');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to URI');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to URI');
case PropertyType::DECIMAL:
- switch ($srctype) {
+ switch ($srcType) {
case PropertyType::STRING:
// TODO: validate
return $value;
@@ -356,17 +380,17 @@ public function convertType($value, $type, $srctype = PropertyType::UNDEFINED)
case PropertyType::DECIMAL:
return (string) $value;
case PropertyType::DATE:
- /** @var $value \DateTime */
+ /* @var $value DateTime */
return (string) $value->getTimestamp();
}
if (is_object($value)) {
- throw new ValueFormatException('Can not convert object of class '.get_class($value).' to a DECIMAL');
+ throw new ValueFormatException('Cannot convert object of class "'.$value::class.'" to a DECIMAL');
}
- throw new ValueFormatException('Can not convert '.var_export($value, true).' to a DECIMAL');
+ throw new ValueFormatException('Cannot convert "'.var_export($value, true).'" to a DECIMAL');
default:
- throw new ValueFormatException("Unexpected target type $type in conversion");
+ throw new ValueFormatException("Unexpected target type '$type' in conversion");
}
}
}
diff --git a/tests/PHPCR/Tests/Stubs/MockNode.php b/tests/PHPCR/Tests/Stubs/MockNode.php
index ea937214..5d27eac6 100644
--- a/tests/PHPCR/Tests/Stubs/MockNode.php
+++ b/tests/PHPCR/Tests/Stubs/MockNode.php
@@ -1,9 +1,14 @@
+ */
abstract class MockNode implements \Iterator, NodeInterface
{
}
diff --git a/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php b/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php
index 97f696f0..f3fe1df2 100644
--- a/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php
+++ b/tests/PHPCR/Tests/Stubs/MockNodeTypeManager.php
@@ -1,9 +1,15 @@
+ */
abstract class MockNodeTypeManager implements \Iterator, NodeTypeManagerInterface
{
}
diff --git a/tests/PHPCR/Tests/Stubs/MockRow.php b/tests/PHPCR/Tests/Stubs/MockRow.php
index 298e2bef..95112378 100644
--- a/tests/PHPCR/Tests/Stubs/MockRow.php
+++ b/tests/PHPCR/Tests/Stubs/MockRow.php
@@ -1,9 +1,14 @@
+ */
abstract class MockRow implements \Iterator, RowInterface
{
}
diff --git a/tests/PHPCR/Tests/Util/CND/Fixtures/files/TestFile.php b/tests/PHPCR/Tests/Util/CND/Fixtures/files/TestFile.php
index 4f3f0988..b8db0e88 100644
--- a/tests/PHPCR/Tests/Util/CND/Fixtures/files/TestFile.php
+++ b/tests/PHPCR/Tests/Util/CND/Fixtures/files/TestFile.php
@@ -5,14 +5,14 @@
class TestClass
{
/**
- * Block comment
+ * Block comment.
*/
public function testMethod($testParam)
{
// Line comment
$string = 'This is a "Test // string"';
- return "Test string";
+ return 'Test string';
}
// String in "comment"
diff --git a/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php b/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php
index 64e30845..48b3e940 100644
--- a/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php
+++ b/tests/PHPCR/Tests/Util/CND/Reader/BufferReaderTest.php
@@ -1,20 +1,38 @@
assertInstanceOf('\PHPCR\Util\CND\Reader\BufferReader', $reader);
- $this->assertAttributeEquals(str_replace("\r\n", "\n", $buffer) . $reader->getEofMarker(), 'buffer', $reader);
- $this->assertAttributeEquals(0, 'startPos', $reader);
- $this->assertAttributeEquals(0, 'forwardPos', $reader);
+ $reflection = new \ReflectionClass($reader);
+ $bufferProperty = $reflection->getProperty('buffer');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $bufferProperty->setAccessible(true);
+ }
+ $this->assertSame(str_replace("\r\n", "\n", $buffer).$reader->getEofMarker(), $bufferProperty->getValue($reader));
+ $startPos = $reflection->getProperty('startPos');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $startPos->setAccessible(true);
+ }
+ $this->assertSame(0, $startPos->getValue($reader));
+ $forwardPos = $reflection->getProperty('forwardPos');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $forwardPos->setAccessible(true);
+ }
+ $this->assertSame(0, $forwardPos->getValue($reader));
$this->assertEquals(1, $reader->getCurrentLine());
$this->assertEquals(1, $reader->getCurrentColumn());
@@ -85,14 +103,29 @@ public function test__construct()
$this->assertEquals($reader->getEofMarker(), $reader->forward());
}
- public function test__constructEmptyString()
+ public function testConstructEmptyString(): void
{
$reader = new BufferReader('');
- $this->assertInstanceOf('\PHPCR\Util\CND\Reader\BufferReader', $reader);
- $this->assertAttributeEquals($reader->getEofMarker(), 'buffer', $reader);
- $this->assertAttributeEquals(0, 'startPos', $reader);
- $this->assertAttributeEquals(0, 'forwardPos', $reader);
+ $reflection = new \ReflectionClass($reader);
+ $buffer = $reflection->getProperty('buffer');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $buffer->setAccessible(true);
+ }
+ $this->assertSame($reader->getEofMarker(), $buffer->getValue($reader));
+ $startPos = $reflection->getProperty('startPos');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $startPos->setAccessible(true);
+ }
+ $this->assertSame(0, $startPos->getValue($reader));
+ $forwardPos = $reflection->getProperty('forwardPos');
+ // remove when we drop PHP 8.0 support
+ if (PHP_VERSION_ID < 80100) {
+ $forwardPos->setAccessible(true);
+ }
+ $this->assertSame(0, $forwardPos->getValue($reader));
$this->assertEquals(1, $reader->getCurrentLine());
$this->assertEquals(1, $reader->getCurrentColumn());
@@ -104,5 +137,4 @@ public function test__constructEmptyString()
$this->assertEquals($reader->getEofMarker(), $reader->forward());
$this->assertEquals($reader->getEofMarker(), $reader->consume());
}
-
}
diff --git a/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php b/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php
index b1397684..ac8d2fbc 100644
--- a/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php
+++ b/tests/PHPCR/Tests/Util/CND/Reader/FileReaderTest.php
@@ -1,51 +1,63 @@
filepath = __DIR__ . '/../Fixtures/files/TestFile.txt';
+ $this->filepath = __DIR__.'/../Fixtures/files/TestFile.txt';
$this->reader = new FileReader($this->filepath);
- $this->lines = array(
+ $lines = [
'This is a test file...',
'',
'...containing dummy content.',
- ''
- );
+ '',
+ ];
$this->chars = array_merge(
- preg_split('//', $this->lines[0], -1, PREG_SPLIT_NO_EMPTY),
- array("\n", "\n"),
- preg_split('//', $this->lines[2], -1, PREG_SPLIT_NO_EMPTY),
- array("\n", "\n")
+ /* @phpstan-ignore argument.type */ // our fixtures are expected to be without error, no need to check if split worked
+ preg_split('//', $lines[0], -1, PREG_SPLIT_NO_EMPTY),
+ ["\n", "\n"],
+ /* @phpstan-ignore argument.type */
+ preg_split('//', $lines[2], -1, PREG_SPLIT_NO_EMPTY),
+ ["\n", "\n"]
);
}
- /**
- * @expectedException \InvalidArgumentException
- */
- public function test__construct_fileNotFound()
+ public function testConstructFileNotFound(): void
{
- $reader = new FileReader('unexisting_file');
+ $this->expectException(\InvalidArgumentException::class);
+
+ new FileReader('unexisting_file');
}
- public function testGetPath()
+ public function testGetPath(): void
{
$this->assertEquals($this->filepath, $this->reader->getPath());
}
- public function testGetNextChar()
+ public function testGetNextChar(): void
{
$curLine = 1;
$curCol = 1;
- for ($i = 0; $i < count($this->chars); $i++) {
-
+ for ($i = 0; $i < count($this->chars); ++$i) {
$peek = $this->reader->currentChar();
if ($peek === $this->reader->getEofMarker()) {
@@ -60,11 +72,11 @@ public function testGetNextChar()
$this->assertFalse($this->reader->isEof());
// Assert isEol is true at end of the lines
- if ($peek === "\n") {
- $curLine++;
+ if ("\n" === $peek) {
+ ++$curLine;
$curCol = 1;
} else {
- $curCol++;
+ ++$curCol;
}
// Assert the next character is the expected one
@@ -84,5 +96,4 @@ public function testGetNextChar()
$this->assertTrue($this->reader->isEof());
$this->assertEquals(false, $this->reader->forwardChar());
}
-
}
diff --git a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php
index eb908fbe..7021b05f 100644
--- a/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php
+++ b/tests/PHPCR/Tests/Util/CND/Scanner/GenericScannerTest.php
@@ -1,122 +1,130 @@
+ */
+ private array $expectedTokens = [
//