Skip to content

Commit

Permalink
Merge pull request #51 from nepda/50-fix-di-problem-with-unnamed-para…
Browse files Browse the repository at this point in the history
…meters

Fix DI problem with Laravel 10 - add names for parameters for container
  • Loading branch information
jimmypuckett authored Apr 8, 2024
2 parents a33f0ff + cfba3e5 commit 20741ce
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 47 deletions.
68 changes: 27 additions & 41 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
This is the "dist(ribution)" phpunit.xml.dist file. It sets the defaults that are then over written by any files in
phpunit.xml, which is then over wrote by flags passed in via the command line. The plan is that this file is to be
used by ci to do the full suit of tests, and a developer can copy this file to phpunit.xml to trim down some of the
options.
-->

<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
verbose="true">

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
verbose="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<exclude>
<directory suffix=".php">src/config</directory>
</exclude>
<report>
<clover outputFile="build/phpunit/logs/clover.xml"/>
<html outputDirectory="./build/phpunit/coverage" lowUpperBound="35" highLowerBound="70"/>
<text outputFile="php://stdout" showUncoveredFiles="false" showOnlySummary="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="Library Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>

<php>
<!-- <env name="VARIABLE" value="value"/> -->
</php>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
<exclude>
<!--<file>src/file.php</file>-->
<directory suffix=".php">src/config</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html"
target="./build/phpunit/coverage"
lowUpperBound="35"
highLowerBound="70"/>
<log type="coverage-text"
target="php://stdout"
showOnlySummary="true"
showUncoveredFiles="false"/>
<log type="coverage-clover" target="build/phpunit/logs/clover.xml"/>
<log type="junit" target="./build/phpunit/logs/junit.xml"/>
<junit outputFile="./build/phpunit/logs/junit.xml"/>
</logging>
</phpunit>
2 changes: 1 addition & 1 deletion src/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ public function parse(object|string $data, ?string $type = null): GeometryProxy
// If running in Laravel, then use the IoC
return is_null($this->app)
? new $geometry_class($geometry, $this->mapper)
: $this->app->make($geometry_class, [$geometry, $this->mapper]);
: $this->app->make($geometry_class, ['geometry' => $geometry, 'mapper' => $this->mapper]);
}
}
2 changes: 1 addition & 1 deletion src/GeometryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function boot()
public function register()
{
$this->app->singleton('geometry', function ($app) {
return $app->make(Geometry::class, [new geoPHP(), new TypeMapper(), $app]);
return $app->make(Geometry::class, ['geometry' => new geoPHP(), 'mapper' => new TypeMapper(), 'app' => $app]);
});
}
}
140 changes: 136 additions & 4 deletions tests/GeometryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ public function it_uses_laravel_to_resolve_classes_if_was_provided()
->withArgs([
'Spinen\Geometry\Geometries\Polygon',
[
$polygon,
$this->mapper_mock,
'geometry' => $polygon,
'mapper' => $this->mapper_mock,
],
])
->andReturn(new GeometryProxy($polygon, $this->mapper_mock));
Expand Down Expand Up @@ -340,12 +340,144 @@ public function it_raises_exception_when_building_name_to_proxy_class_for_null_g
*/
public function it_raises_exception_when_building_name_to_proxy_class_that_does_not_exist()
{
$this->markTestSkipped('Now that typecasting a Geometry, there is no way to pass an invalid class to trigger this test');

$this->expectException(RuntimeException::class);

$this->geometry->buildGeometryClassName(new class extends GlobalGeometry
{
public function area()
{
// Just a stub for area() method.
}

public function boundary()
{
// Just a stub for boundary() method.
}

public function centroid()
{
// Just a stub for centroid() method.
}

public function length()
{
// Just a stub for length() method.
}

public function y()
{
// Just a stub for y() method.
}

public function x()
{
// Just a stub for x() method.
}

public function numGeometries()
{
// Just a stub for numGeometries() method.
}

public function geometryN($n)
{
// Just a stub for geometryN() method.
}

public function startPoint()
{
// Just a stub for startPoint() method.
}

public function endPoint()
{
// Just a stub for endPoint() method.
}

public function isRing()
{
// Just a stub for isRing() method.
}

public function isClosed()
{
// Just a stub for isClosed() method.
}

public function numPoints()
{
// Just a stub for numPoints() method.
}

public function pointN($n)
{
// Just a stub for pointN() method.
}

public function exteriorRing()
{
// Just a stub for exteriorRing() method.
}

public function numInteriorRings()
{
// Just a stub for numInteriorRings() method.
}

public function interiorRingN($n)
{
// Just a stub for interiorRingN() method.
}

public function dimension()
{
// Just a stub for dimension() method.
}

public function equals($geom)
{
// Just a stub for equals() method.
}

public function isEmpty()
{
// Just a stub for isEmpty() method.
}

public function isSimple()
{
// Just a stub for isSimple() method.
}

public function getBBox()
{
// Just a stub for getBBox() method.
}

public function asArray()
{
// Just a stub for asArray() method.
}

public function getPoints()
{
// Just a stub for getPoints() method.
}

public function explode()
{
// Just a stub for explode() method.
}

public function greatCircleLength()
{
// Just a stub for greatCircleLength() method.
}

public function haversineLength()
{
// Just a stub for haversineLength() method.
}
});
}
}

0 comments on commit 20741ce

Please sign in to comment.