-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Closes #19 ## Checklist - [x] Updated CHANGELOG files - [x] Updated Documentation - [x] Unit Tests Created - [x] php-cs-fixer
- Loading branch information
1 parent
d5778b2
commit 7be1fb4
Showing
35 changed files
with
476 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/Tests export-ignore | ||
/phpunit.xml.dist export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
composer.lock | ||
phpunit.xml | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright 2022 to Present Joshua Estes | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Bridge\Twig\Money; | ||
|
||
use SonsOfPHP\Contract\Money\MoneyFormatterInterface; | ||
use SonsOfPHP\Contract\Money\MoneyInterface; | ||
use Twig\Extension\AbstractExtension; | ||
use Twig\TwigFilter; | ||
|
||
/** | ||
*/ | ||
class MoneyExtension extends AbstractExtension | ||
{ | ||
public function __construct( | ||
private MoneyFormatterInterface $formatter, | ||
) {} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFilters(): array | ||
{ | ||
return [ | ||
new TwigFilter('format_money', [$this, 'formatMoney']), | ||
]; | ||
} | ||
|
||
/** | ||
* Formats money | ||
* | ||
* Examples | ||
* MoneyInterface|format_money | ||
*/ | ||
public function formatMoney(MoneyInterface $money): string | ||
{ | ||
return $this->formatter->format($money); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Sons of PHP - Money - Twig Bridge | ||
================================= | ||
|
||
## Learn More | ||
|
||
* [Documentation][docs] | ||
* [Contributing][contributing] | ||
* [Report Issues][issues] and [Submit Pull Requests][pull-requests] in the | ||
[Mother Repository][mother-repo] | ||
* Get Help & Support using [Discussions][discussions] | ||
|
||
[discussions]: https://github.com/orgs/SonsOfPHP/discussions | ||
[mother-repo]: https://github.com/SonsOfPHP/sonsofphp | ||
[contributing]: https://docs.sonsofphp.com/contributing/ | ||
[docs]: https://docs.sonsofphp.com/components/money/ | ||
[issues]: https://github.com/SonsOfPHP/sonsofphp/issues?q=is%3Aopen+is%3Aissue+label%3AMoney | ||
[pull-requests]: https://github.com/SonsOfPHP/sonsofphp/pulls?q=is%3Aopen+is%3Apr+label%3AMoney |
60 changes: 60 additions & 0 deletions
60
src/SonsOfPHP/Bridge/Twig/Money/Tests/MoneyExtensionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SonsOfPHP\Bridge\Twig\Money\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SonsOfPHP\Bridge\Twig\Money\MoneyExtension; | ||
use SonsOfPHP\Component\Money\Money; | ||
use SonsOfPHP\Contract\Money\MoneyFormatterInterface; | ||
use Twig\Extension\ExtensionInterface; | ||
|
||
/** | ||
* @coversDefaultClass \SonsOfPHP\Bridge\Twig\Money\MoneyExtension | ||
* | ||
* @uses \SonsOfPHP\Component\Money\Amount | ||
* @uses \SonsOfPHP\Component\Money\Currency | ||
* @uses \SonsOfPHP\Component\Money\Money | ||
* @uses \SonsOfPHP\Bridge\Twig\Money\MoneyExtension | ||
*/ | ||
final class MoneyExtensionTest extends TestCase | ||
{ | ||
private $formatter; | ||
|
||
public function setUp(): void | ||
{ | ||
$this->formatter = $this->createMock(MoneyFormatterInterface::class); | ||
} | ||
|
||
/** | ||
* @covers ::__construct | ||
*/ | ||
public function testItHasTheRightInterface(): void | ||
{ | ||
$extension = new MoneyExtension($this->formatter); | ||
|
||
$this->assertInstanceOf(ExtensionInterface::class, $extension); | ||
} | ||
|
||
/** | ||
* @covers ::getFilters | ||
*/ | ||
public function testGetFilters(): void | ||
{ | ||
$extension = new MoneyExtension($this->formatter); | ||
|
||
$this->assertGreaterThan(0, $extension->getFilters()); | ||
} | ||
|
||
/** | ||
* @covers ::formatMoney | ||
*/ | ||
public function testItCanFormatMoney(): void | ||
{ | ||
$this->formatter->expects($this->once())->method('format')->willReturn(''); | ||
|
||
$extension = new MoneyExtension($this->formatter); | ||
$extension->formatMoney(Money::USD(10)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "sonsofphp/money-twig", | ||
"type": "library", | ||
"description": "Twig Extension for the Money Component", | ||
"keywords": [ | ||
"money", | ||
"currency", | ||
"ISO4217" | ||
], | ||
"homepage": "https://github.com/SonsOfPHP/money", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Joshua Estes", | ||
"email": "joshua@sonsofphp.com" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/SonsOfPHP/sonsofphp/issues", | ||
"forum": "https://github.com/orgs/SonsOfPHP/discussions", | ||
"docs": "https://docs.sonsofphp.com" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"SonsOfPHP\\Bridge\\Twig\\Money\\": "" | ||
}, | ||
"exclude-from-classmap": [ | ||
"/Tests/" | ||
] | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=8.1", | ||
"sonsofphp/money": "^0.3.x-dev", | ||
"twig/twig": "^3.0" | ||
}, | ||
"extra": { | ||
"sort-packages": true, | ||
"branch-alias": { | ||
"dev-main": "0.3.x-dev" | ||
} | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/JoshuaEstes" | ||
}, | ||
{ | ||
"type": "tidelift", | ||
"url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.