Skip to content

Commit

Permalink
Drop usage of icanboogie/common
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Nov 2, 2024
1 parent cc207f0 commit 454dd86
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 48 deletions.
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@
"php": ">=8.2"
},
"require-dev": {
"icanboogie/common": "^2.0",
"phpunit/phpunit": "^11.4"
},
"suggest": {
"icanboogie/common": "Allows finer exceptions to be thrown"
},
"autoload": {
"psr-4": {
"ICanBoogie\\": "lib"
Expand Down
35 changes: 9 additions & 26 deletions lib/DateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,9 @@ public function __get($property)
return $transitions[0]['isdst'];
}

if (class_exists(PropertyNotDefined::class))
{
throw new PropertyNotDefined([ $property, $this ]);
}
else
{
throw new RuntimeException("Property is not defined: $property.");
}
throw new \LogicException(
sprintf("Undefined property: %s::%s", $this::class, $property)
);
}

/**
Expand Down Expand Up @@ -533,8 +528,6 @@ private function get_sunday(): self
* Sets the {@see $year}, {@see $month}, {@see $day}, {@see $hour}, {@see $minute},
* {@see $second}, {@see $timestamp} and {@see $zone} properties.
*
* @throws PropertyNotWritable in an attempt to set a read-only property.
* @throws PropertyNotDefined in an attempt to set an unsupported property.
* @throws \DateInvalidTimeZoneException
*/
public function __set($property, $value): void
Expand Down Expand Up @@ -565,24 +558,14 @@ public function __set($property, $value): void
|| method_exists($this, 'get_' . $property)
)
{
if (class_exists(PropertyNotWritable::class))
{
throw new PropertyNotWritable([ $property, $this ]);
}
else
{
throw new RuntimeException("Property is not writeable: $property.");
}
throw new \LogicException(
sprintf("Readonly property: %s::%s", $this::class, $property)
);
}

if (class_exists(PropertyNotDefined::class))
{
throw new PropertyNotDefined([ $property, $this ]);
}
else
{
throw new RuntimeException("Property is not defined: $property.");
}
throw new \LogicException(
sprintf("Undefined property: %s::%s", $this::class, $property),
);
}

/**
Expand Down
11 changes: 3 additions & 8 deletions lib/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,9 @@ public function __get(string $property)
return $this->getOffset($utc_time);
}

if (class_exists(PropertyNotDefined::class))
{
throw new PropertyNotDefined([ $property, $this ]);
}
else
{
throw new \RuntimeException("Property no defined: $property.");
}
throw new \LogicException(
sprintf("Undefined property: %s::%s", $this::class, $property),
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
bootstrap="./vendor/autoload.php"
bootstrap="vendor/autoload.php"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerNotices="true"
Expand Down
13 changes: 5 additions & 8 deletions tests/DateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Test\ICanBoogie;

use ICanBoogie\DateTime;
use ICanBoogie\PropertyNotDefined;
use ICanBoogie\PropertyNotWritable;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Test\ICanBoogie\DateTimeTest\MyDateTime;
Expand All @@ -24,8 +22,7 @@ public function test_readonly(string $property): void
{
$d = DateTime::now();

$this->expectExceptionMessage("The property `$property` for object of class `ICanBoogie\DateTime` is not writable.");
$this->expectException(PropertyNotWritable::class);
$this->expectExceptionMessage("Readonly property: ICanBoogie\DateTime::$property");
$d->{ $property } = null;
}

Expand Down Expand Up @@ -153,7 +150,7 @@ public function test_change()
'day' => 1,
'hour' => 1,
'minute' => 1,
'second' => 1
'second' => 1,

]);

Expand Down Expand Up @@ -1003,12 +1000,12 @@ public function test_localize(): void
$this->assertTrue($invoked);
}

public function test_getting_undefined_property_should_throw_exception()
public function test_getting_undefined_property_should_trigger_a_warning()
{
$date = DateTime::now();
$property = uniqid();
$this->expectException(PropertyNotDefined::class);
$this->expectExceptionMessage("Undefined property `$property` for object of class `ICanBoogie\DateTime`.");

$this->expectExceptionMessage("Undefined property: ICanBoogie\DateTime::$property");
$date->$property;
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/TimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public function test_getting_undefined_property_should_throw_exception(): void
{
$property = uniqid();
$z1 = TimeZone::from('utc');
$this->expectException(PropertyNotDefined::class);

$this->expectExceptionMessage("Undefined property: ICanBoogie\TimeZone::$property");
$z1->$property;
}

Expand Down

0 comments on commit 454dd86

Please sign in to comment.