-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b57b64a
Showing
15 changed files
with
576 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.github/ export-ignore | ||
phpunit.xml export-ignore | ||
phpunit-bootstrap.php export-ignore | ||
psalm.xml export-ignore | ||
tests/ 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 @@ | ||
github: BenMorel |
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,74 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
psalm: | ||
name: Psalm | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "8.0" | ||
|
||
- name: Install composer dependencies | ||
uses: "ramsey/composer-install@v1" | ||
|
||
- name: Run Psalm | ||
run: vendor/bin/psalm --show-info=false --find-unused-psalm-suppress --no-progress | ||
|
||
phpunit: | ||
name: PHPUnit | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
php-version: | ||
- "7.1" | ||
- "7.2" | ||
- "7.3" | ||
- "7.4" | ||
- "8.0" | ||
deps: | ||
- "highest" | ||
include: | ||
- php-version: "7.1" | ||
deps: "lowest" | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-version }} | ||
coverage: xdebug | ||
|
||
- name: Install composer dependencies | ||
uses: "ramsey/composer-install@v1" | ||
with: | ||
dependency-versions: ${{ matrix.deps }} | ||
|
||
- name: Run PHPUnit | ||
run: vendor/bin/phpunit | ||
if: ${{ matrix.php-version != '8.0' }} | ||
|
||
- name: Run PHPUnit with coverage | ||
run: | | ||
mkdir -p mkdir -p build/logs | ||
vendor/bin/phpunit --coverage-clover build/logs/clover.xml | ||
if: ${{ matrix.php-version == '8.0' }} | ||
|
||
- name: Upload coverage report to Coveralls | ||
run: vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v | ||
env: | ||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
if: ${{ matrix.php-version == '8.0' }} |
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 @@ | ||
/vendor | ||
/composer.lock | ||
/.phpunit.result.cache |
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2021-present Benjamin Morel | ||
|
||
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,46 @@ | ||
brick/phonenumber-doctrine | ||
======================== | ||
|
||
<img src="https://raw.githubusercontent.com/brick/brick/master/logo.png" alt="" align="left" height="64"> | ||
|
||
Doctrine type mappings for [brick/phonenumber](https://github.com/brick/phonenumber). | ||
|
||
[![Build Status](https://github.com/brick/phonenumber-doctrine/workflows/CI/badge.svg)](https://github.com/brick/phonenumber-doctrine/actions) | ||
[![Coverage Status](https://coveralls.io/repos/github/brick/phonenumber-doctrine/badge.svg?branch=master)](https://coveralls.io/github/brick/phonenumber-doctrine?branch=master) | ||
[![Latest Stable Version](https://poser.pugx.org/brick/phonenumber-doctrine/v/stable)](https://packagist.org/packages/brick/phonenumber-doctrine) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) | ||
|
||
Introduction | ||
------------ | ||
|
||
This library provides a type mapping to use `PhoneNumber` objects as Doctrine entity properties. | ||
|
||
Installation | ||
------------ | ||
|
||
This library is installable via [Composer](https://getcomposer.org/): | ||
|
||
```bash | ||
composer require brick/phonenumber-doctrine | ||
``` | ||
|
||
Requirements | ||
------------ | ||
|
||
This library requires PHP 7.1 or later. | ||
|
||
Project status & release process | ||
-------------------------------- | ||
|
||
The current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), `y` is incremented. | ||
|
||
**When a breaking change is introduced, a new `0.x` version cycle is always started.** | ||
|
||
It is therefore safe to lock your project to a given release cycle, such as `0.1.*`. | ||
|
||
If you need to upgrade to a newer release cycle, check the [release history](https://github.com/brick/phonenumber-doctrine/releases) for a list of changes introduced by each further `0.x.0` version. | ||
|
||
Package contents | ||
---------------- | ||
|
||
- [PhoneNumberType](https://github.com/brick/phonenumber-doctrine/blob/master/src/Types/PhoneNumberType.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,34 @@ | ||
{ | ||
"name": "brick/phonenumber-doctrine", | ||
"description": "Doctrine type mappings for brick/phonenumber", | ||
"type": "library", | ||
"keywords": [ | ||
"Brick", | ||
"PhoneNumber", | ||
"Doctrine" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"brick/phonenumber": "~0.2.0 || ~0.3.0", | ||
"doctrine/dbal": "^2.7.0", | ||
"doctrine/orm": "^2.6.0", | ||
"php": "^7.1 || ^8.0" | ||
}, | ||
"require-dev": { | ||
"ext-pdo": "*", | ||
"ext-pdo_sqlite": "*", | ||
"phpunit/phpunit": "^7.5.15 || ^8.0 || ^9.0", | ||
"php-coveralls/php-coveralls": "^2.4", | ||
"vimeo/psalm": "^4.9" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Brick\\PhoneNumber\\Doctrine\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Brick\\PhoneNumber\\Doctrine\\Tests\\": "tests/" | ||
} | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Brick\PhoneNumber\Doctrine\Types\PhoneNumberType; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
Type::addType('PhoneNumber', PhoneNumberType::class); |
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="phpunit-bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<testsuites> | ||
<testsuite name="PhoneNumber Doctrine tests"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
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,15 @@ | ||
<?xml version="1.0"?> | ||
<psalm | ||
errorLevel="1" | ||
resolveFromConfigFile="true" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="https://getpsalm.org/schema/config" | ||
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" | ||
> | ||
<projectFiles> | ||
<directory name="src" /> | ||
<ignoreFiles> | ||
<directory name="vendor" /> | ||
</ignoreFiles> | ||
</projectFiles> | ||
</psalm> |
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,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\PhoneNumber\Doctrine\Types; | ||
|
||
use Brick\PhoneNumber\PhoneNumber; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\ConversionException; | ||
use Doctrine\DBAL\Types\Type; | ||
|
||
final class PhoneNumberType extends Type | ||
{ | ||
public function getName() | ||
{ | ||
return 'PhoneNumber'; | ||
} | ||
|
||
public function convertToDatabaseValue($value, AbstractPlatform $platform) | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
if ($value instanceof PhoneNumber) { | ||
return (string) $value; | ||
} | ||
|
||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), [PhoneNumber::class, 'null']); | ||
} | ||
|
||
public function convertToPHPValue($value, AbstractPlatform $platform) | ||
{ | ||
if ($value === null) { | ||
return null; | ||
} | ||
|
||
if (is_string($value)) { | ||
return PhoneNumber::parse($value); | ||
} | ||
|
||
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['string', 'null']); | ||
} | ||
|
||
public function getSQLDeclaration(array $column, AbstractPlatform $platform) | ||
{ | ||
// E.164 defines the maximum length as 15 digits, to which we add 1 char for the leading + sign. | ||
if (!isset($column['length'])) { | ||
$column['length'] = 16; | ||
} | ||
|
||
return $platform->getVarcharTypeDeclarationSQL($column); | ||
} | ||
|
||
public function requiresSQLCommentHint(AbstractPlatform $platform) | ||
{ | ||
return true; | ||
} | ||
} |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\PhoneNumber\Doctrine\Tests; | ||
|
||
use Brick\PhoneNumber\Doctrine\Tests\Entity\User; | ||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\DriverManager; | ||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\EntityManager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class AbstractFunctionalTest extends TestCase | ||
{ | ||
final protected static function createConnection(): Connection | ||
{ | ||
return DriverManager::getConnection(['url' => 'sqlite:///:memory:']); | ||
} | ||
|
||
final protected static function createEntityManager(Connection $connection): EntityManager | ||
{ | ||
return EntityManager::create($connection, self::createConfiguration()); | ||
} | ||
|
||
private static function createConfiguration(): Configuration | ||
{ | ||
$config = new Configuration(); | ||
|
||
$driverImpl = $config->newDefaultAnnotationDriver([__DIR__ . '/tests/Entity'], false); | ||
$config->setMetadataDriverImpl($driverImpl); | ||
|
||
$config->setProxyDir(sys_get_temp_dir()); | ||
$config->setProxyNamespace('Brick\PhoneNumber\Doctrine\Tests\Proxy'); | ||
|
||
return $config; | ||
} | ||
|
||
final protected static function truncateEntityTable(EntityManager $em): void | ||
{ | ||
$em->createQueryBuilder() | ||
->delete(User::class, 's') | ||
->getQuery() | ||
->execute(); | ||
} | ||
|
||
final protected function getFirstEntity(EntityManager $em): ?User | ||
{ | ||
return $em->createQueryBuilder() | ||
->select('s') | ||
->from(User::class, 's') | ||
->getQuery() | ||
->getOneOrNullResult(); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\PhoneNumber\Doctrine\Tests\Entity; | ||
|
||
use Brick\PhoneNumber\PhoneNumber; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ORM\Entity | ||
*/ | ||
class User | ||
{ | ||
/** | ||
* @ORM\Id | ||
* @ORM\Column(type="integer") | ||
* @ORM\GeneratedValue | ||
* | ||
* @var int | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @ORM\Column(type="PhoneNumber", nullable=true) | ||
* | ||
* @var PhoneNumber|null | ||
*/ | ||
public $phoneNumber = null; | ||
} |
Oops, something went wrong.