Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
Improve Package
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 9, 2016
1 parent 740a258 commit cd2eaa7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All Notable changes to `uri-manipulations` will be documented in this file

## 0.2.0 - 2016-12-09

### Added

- None

### Fixed

- Updated dependencies to `League\Uri\Components`
- bug fix to path modifiers see [issue #91](https://github.com/thephpleague/uri/issues/91)

### Deprecated

- None

### Removed

## 0.1.0 - 2016-12-01

### Added
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
"require": {
"php" : ">=5.6",
"psr/http-message": "^1.0",
"league/uri-components": "~0.4",
"league/uri-interfaces": "~0.2"
"league/uri-components": "~0.5"
},
"require-dev": {
"league/uri-schemes": "~0.3",
"league/uri-schemes": "~0.4",
"guzzlehttp/psr7": "^1.2",
"league/uri-parser": "~0.2",
"friendsofphp/php-cs-fixer": "^1.9",
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
stopOnFailure="false">

<testsuites>
<testsuite name="Uri Manipulation Test Suite">
<testsuite name="Uri Manipulations Test Suite">
<directory>test</directory>
</testsuite>
</testsuites>
Expand All @@ -27,7 +27,6 @@
</filter>

<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-text" target="build/coverage.txt"/>
Expand Down
7 changes: 6 additions & 1 deletion src/ManipulatePath.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public function __invoke($payload)
{
$this->assertUriObject($payload);

return $payload->withPath($this->modifyPath($payload->getPath()));
$path = $this->modifyPath($payload->getPath());
if ('' != $payload->getAuthority() && '' != $path && '/' != $path[0]) {
$path = '/'.$path;
}

return $payload->withPath($path);
}

/**
Expand Down
35 changes: 35 additions & 0 deletions test/PathModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ public function testAppendProcess($segment, $key, $append, $prepend, $replace)
$this->assertSame($append, $modifier($this->uri)->getPath());
}

/**
* @dataProvider validAppendPathProvider
*/
public function testAppendProcessWithRelativePath($uri, $segment, $expected)
{
$modifier = new AppendSegment($segment);
$this->assertSame($expected, (string) $modifier(Http::createFromString($uri)));
}
public function validAppendPathProvider()
{
return [
'uri with trailing slash' => [
'uri' => 'http://www.example.com/report/',
'segment' => 'new-segment',
'expected' => 'http://www.example.com/report/new-segment',
],
'uri with path without trailing slash' => [
'uri' => 'http://www.example.com/report',
'segment' => 'new-segment',
'expected' => 'http://www.example.com/report/new-segment',
],
'uri with absolute path' => [
'uri' => 'http://www.example.com/',
'segment' => 'new-segment',
'expected' => 'http://www.example.com/new-segment',
],
'uri with empty path' => [
'uri' => 'http://www.example.com',
'segment' => 'new-segment',
'expected' => 'http://www.example.com/new-segment',
],
];
}


/**
* @dataProvider validPathProvider
*
Expand Down

0 comments on commit cd2eaa7

Please sign in to comment.