initial commit

This commit is contained in:
2021-12-20 12:50:53 +01:00
commit 839913d51a
51 changed files with 13051 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testConstructor extends TestCase
{
/**
* Non-regression test for Github issue #5
* https://github.com/biblys/isbn/pull/5
*/
public function testUnknownPrefix()
{
$isbn = new Isbn("9790706801940");
$this->expectNotToPerformAssertions("Should not throw");
}
}

View File

@ -0,0 +1,76 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testFormatIsbn extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecatedNotice()
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->format is deprecated and will be removed in the future. Use the Isbn::convertToIsbn13 method instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782207258040');
$isbn->format('ISBN-13');
}
public function testFormatIsbn13()
{
$isbn = new Isbn('9782207258040');
$this->assertEquals($isbn->format('ISBN-13'), "978-2-207-25804-0");
}
public function testFormatIsbn10()
{
$isbn10 = new Isbn('9783464603529');
$this->assertEquals($isbn10->format('ISBN-10'), "3-464-60352-0");
}
public function testFormatEan13()
{
$isbn10 = new Isbn("978-2-207-25804-0");
$this->assertEquals($isbn10->format('EAN'), "9782207258040");
}
public function testFormatEan_13()
{
$isbn10 = new Isbn("978-2-207-25804-0");
$this->assertEquals($isbn10->format('EAN-13'), "9782207258040");
}
public function testFormatGtin14()
{
$isbn = new Isbn('9783464603529');
$this->assertEquals($isbn->format('GTIN-14'), '19783464603526');
}
public function testMauritiusRange()
{
$isbn = new Isbn('9786130971311');
$this->assertEquals($isbn->format('ISBN-13'), "978-613-0-97131-1");
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testGetErrors extends TestCase
{
public function testDeprecatedNotice()
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->getErrors is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn("6897896354577");
$isbn->getErrors();
}
public function testInvalidIsbn()
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
$isbn = new Isbn("6897896354577");
$this->assertEquals($isbn->getErrors(), '[6897896354577] Product code should be 978 or 979');
}
}

View File

@ -0,0 +1,65 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testIsbnIsValid extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecationNotice(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->isValid is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782207258040');
$isbn->isValid();
}
public function testIsValid()
{
$isbn = new Isbn('9782207258040');
$this->assertTrue($isbn->isValid());
}
public function testIsNotValid()
{
$invalid = new Isbn('5780AAC728440');
$this->assertFalse($invalid->isValid());
}
public function testIsbn10WithChecksumX()
{
$isbn = new ISBN('80-7203-717-X');
$this->assertTrue($isbn->isValid());
}
public function testValidateMexicanIsbn()
{
$isbn = new Isbn("9700764923");
$this->assertTrue($isbn->isValid());
}
}

View File

@ -0,0 +1,66 @@
<?php
/*
* This file is part of the biblys/isbn package.
*
* (c) Clément Bourgoin
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/../../vendor/autoload.php';
use Biblys\Isbn\Isbn as Isbn;
use PHPUnit\Framework\TestCase;
class testValidateIsbn extends TestCase
{
protected function setUp(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = false;
}
public function testDeprecatedNotice(): void
{
PHPUnit\Framework\Error\Deprecated::$enabled = true;
$this->expectException('PHPUnit\Framework\Error\Deprecated');
$this->expectExceptionMessage(
"Isbn->validate is deprecated and will be removed in the future. Use Isbn::validateAs… methods instead. Learn more: https://git.io/JtAEx"
);
$isbn = new Isbn('9782843449499');
$isbn->validate();
}
public function testValidateValidIsbn()
{
$isbn = new Isbn('9782843449499');
$this->assertTrue($isbn->validate());
}
/**
* Non-regression test for Github issue #6
* https://github.com/biblys/isbn/issues/6
*/
public function testValidateIsbn10WithChecksumX()
{
$isbn = new Isbn('80-7203-717-X');
$this->assertTrue($isbn->validate());
}
/**
* Non-regression test for Github issue #21
* https://github.com/biblys/isbn/issues/21
*/
public function testValidateMexicanIsbn()
{
$isbn = new Isbn("9700764923");
$this->assertTrue($isbn->validate());
}
}