Skip to content

EspoCRM – Open Source CRM Application

exception fix

Yurii5fefed593381
diff --git a/application/Espo/Core/Field/Currency.php b/application/Espo/Core/Field/Currency.php
index 036a27b658..e00350838d 100644
--- a/application/Espo/Core/Field/Currency.php
+++ b/application/Espo/Core/Field/Currency.php
@@ -31,7 +31,6 @@ namespace Espo\Core\Field;
use Espo\Core\Currency\CalculatorUtil;
-use RuntimeException;
use InvalidArgumentException;
/**
@@ -46,7 +45,7 @@ class Currency
/**
* @param numeric-string|float|int $amount An amount.
* @param string $code A currency code.
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function __construct($amount, string $code)
{
@@ -55,7 +54,7 @@ class Currency
}
if (strlen($code) !== 3) {
- throw new RuntimeException("Bad currency code.");
+ throw new InvalidArgumentException("Bad currency code.");
}
if (is_float($amount) || is_int($amount)) {
@@ -95,12 +94,12 @@ class Currency
/**
* Add a currency value.
*
- * @throws RuntimeException If currency codes are different.
+ * @throws InvalidArgumentException If currency codes are different.
*/
public function add(self $value): self
{
if ($this->getCode() !== $value->getCode()) {
- throw new RuntimeException("Can't add a currency value with a different code.");
+ throw new InvalidArgumentException("Can't add a currency value with a different code.");
}
$amount = CalculatorUtil::add(
@@ -114,12 +113,12 @@ class Currency
/**
* Subtract a currency value.
*
- * @throws RuntimeException If currency codes are different.
+ * @throws InvalidArgumentException If currency codes are different.
*/
public function subtract(self $value): self
{
if ($this->getCode() !== $value->getCode()) {
- throw new RuntimeException("Can't subtract a currency value with a different code.");
+ throw new InvalidArgumentException("Can't subtract a currency value with a different code.");
}
$amount = CalculatorUtil::subtract(
@@ -176,12 +175,12 @@ class Currency
* - `0` if equal to the value;
* - `-1` if less than the value.
*
- * @throws RuntimeException If currency codes are different.
+ * @throws InvalidArgumentException If currency codes are different.
*/
public function compare(self $value): int
{
if ($this->getCode() !== $value->getCode()) {
- throw new RuntimeException("Can't compare currencies with different codes.");
+ throw new InvalidArgumentException("Can't compare currencies with different codes.");
}
return CalculatorUtil::compare(
@@ -203,7 +202,7 @@ class Currency
*
* @param numeric-string|float|int $amount An amount.
* @param string $code A currency code.
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public static function create($amount, string $code): self
{
diff --git a/application/Espo/Core/Field/Date.php b/application/Espo/Core/Field/Date.php
index ab61260839..211e2a3f6c 100644
--- a/application/Espo/Core/Field/Date.php
+++ b/application/Espo/Core/Field/Date.php
@@ -35,6 +35,7 @@ use DateTimeImmutable;
use DateTimeInterface;
use DateInterval;
use DateTimeZone;
+use InvalidArgumentException;
use RuntimeException;
/**
@@ -45,12 +46,15 @@ class Date implements DateTimeable
private string $value;
private DateTimeImmutable $dateTime;
- private const SYSTEM_FORMAT = 'Y-m-d';
+ private const string SYSTEM_FORMAT = 'Y-m-d';
+ /**
+ * @throws InvalidArgumentException
+ */
public function __construct(string $value)
{
if (!$value) {
- throw new RuntimeException("Empty value.");
+ throw new InvalidArgumentException("Empty value.");
}
$this->value = $value;
@@ -62,13 +66,13 @@ class Date implements DateTimeable
);
if ($parsedValue === false) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
$this->dateTime = $parsedValue;
if ($this->value !== $this->dateTime->format(self::SYSTEM_FORMAT)) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
}
@@ -259,6 +263,8 @@ class Date implements DateTimeable
/**
* Create from a string with a date in `Y-m-d` format.
+ *
+ * @throws InvalidArgumentException
*/
public static function fromString(string $value): self
{
diff --git a/application/Espo/Core/Field/DateTime.php b/application/Espo/Core/Field/DateTime.php
index 7b2699f687..eab8459300 100644
--- a/application/Espo/Core/Field/DateTime.php
+++ b/application/Espo/Core/Field/DateTime.php
@@ -36,6 +36,7 @@ use DateTimeInterface;
use DateInterval;
use DateTimeZone;
use RuntimeException;
+use InvalidArgumentException;
/**
* A date-time value object. Immutable.
@@ -45,12 +46,15 @@ class DateTime implements DateTimeable
private string $value;
private DateTimeImmutable $dateTime;
- private const SYSTEM_FORMAT = 'Y-m-d H:i:s';
+ private const string SYSTEM_FORMAT = 'Y-m-d H:i:s';
+ /**
+ * @throws InvalidArgumentException
+ */
public function __construct(string $value)
{
if (!$value) {
- throw new RuntimeException("Empty value.");
+ throw new InvalidArgumentException("Empty value.");
}
$normValue = strlen($value) === 16 ? $value . ':00' : $value;
@@ -64,13 +68,13 @@ class DateTime implements DateTimeable
);
if ($parsedValue === false) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
$this->dateTime = $parsedValue;
if ($this->value !== $this->dateTime->format(self::SYSTEM_FORMAT)) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
}
@@ -343,6 +347,8 @@ class DateTime implements DateTimeable
/**
* Create from a string with a date-time in `Y-m-d H:i:s` format.
+ *
+ * @throws InvalidArgumentException
*/
public static function fromString(string $value): self
{
diff --git a/application/Espo/Core/Field/DateTimeOptional.php b/application/Espo/Core/Field/DateTimeOptional.php
index 9f7737417d..2aa407203b 100644
--- a/application/Espo/Core/Field/DateTimeOptional.php
+++ b/application/Espo/Core/Field/DateTimeOptional.php
@@ -35,7 +35,7 @@ use DateTimeImmutable;
use DateTimeInterface;
use DateInterval;
use DateTimeZone;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A date-time or date. Immutable.
@@ -45,9 +45,12 @@ class DateTimeOptional implements DateTimeable
private ?DateTime $dateTimeValue = null;
private ?Date $dateValue = null;
- private const SYSTEM_FORMAT = 'Y-m-d H:i:s';
- private const SYSTEM_FORMAT_DATE = 'Y-m-d';
+ private const string SYSTEM_FORMAT = 'Y-m-d H:i:s';
+ private const string SYSTEM_FORMAT_DATE = 'Y-m-d';
+ /**
+ * @throws InvalidArgumentException
+ */
public function __construct(string $value)
{
if (self::isStringDateTime($value)) {
@@ -59,6 +62,8 @@ class DateTimeOptional implements DateTimeable
/**
* Create from a string with a date-time in `Y-m-d H:i:s` format or date in `Y-m-d`.
+ *
+ * @throws InvalidArgumentException
*/
public static function fromString(string $value): self
{
@@ -67,12 +72,14 @@ class DateTimeOptional implements DateTimeable
/**
* Create from a string with a date-time in `Y-m-d H:i:s` format.
+ *
+ * @throws InvalidArgumentException
* @noinspection PhpUnused
*/
public static function fromDateTimeString(string $value): self
{
if (!self::isStringDateTime($value)) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
return self::fromString($value);
@@ -434,12 +441,14 @@ class DateTimeOptional implements DateTimeable
/**
* Create from a string with a date in `Y-m-d` format.
+ *
+ * @throws InvalidArgumentException
* @noinspection PhpUnused
*/
public static function fromDateString(string $value): self
{
if (self::isStringDateTime($value)) {
- throw new RuntimeException("Bad value.");
+ throw new InvalidArgumentException("Bad value.");
}
return self::fromString($value);
diff --git a/application/Espo/Core/Field/EmailAddress.php b/application/Espo/Core/Field/EmailAddress.php
index b8a4a6a0ab..42ce8edd7f 100644
--- a/application/Espo/Core/Field/EmailAddress.php
+++ b/application/Espo/Core/Field/EmailAddress.php
@@ -29,9 +29,9 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
-use FILTER_VALIDATE_EMAIL;
+use const FILTER_VALIDATE_EMAIL;
/**
* An email address value. Immutable.
@@ -42,14 +42,17 @@ class EmailAddress
private bool $isOptedOut = false;
private bool $isInvalid = false;
+ /**
+ * @throws InvalidArgumentException
+ */
public function __construct(string $address)
{
if ($address === '') {
- throw new RuntimeException("Empty email address.");
+ throw new InvalidArgumentException("Empty email address.");
}
if (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
- throw new RuntimeException("Not valid email address '{$address}'.");
+ throw new InvalidArgumentException("Not valid email address '$address'.");
}
$this->address = $address;
@@ -129,6 +132,8 @@ class EmailAddress
/**
* Create from an address.
+ *
+ * @throws InvalidArgumentException
*/
public static function create(string $address): self
{
diff --git a/application/Espo/Core/Field/EmailAddressGroup.php b/application/Espo/Core/Field/EmailAddressGroup.php
index f660f0957e..4ed503d51b 100644
--- a/application/Espo/Core/Field/EmailAddressGroup.php
+++ b/application/Espo/Core/Field/EmailAddressGroup.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* An email address group. Contains a list of email addresses. One email address is set as primary.
@@ -43,7 +43,7 @@ class EmailAddressGroup
/**
* @param EmailAddress[] $list
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function __construct(array $list = [])
{
@@ -80,11 +80,7 @@ class EmailAddressGroup
{
$primary = $this->getPrimary();
- if (!$primary) {
- return null;
- }
-
- return $primary->getAddress();
+ return $primary?->getAddress();
}
/**
@@ -274,17 +270,20 @@ class EmailAddressGroup
return null;
}
+ /**
+ * @throws InvalidArgumentException
+ */
private function validateList(): void
{
$addressList = [];
foreach ($this->list as $item) {
if (!$item instanceof EmailAddress) {
- throw new RuntimeException("Bad item.");
+ throw new InvalidArgumentException("Bad item.");
}
if (in_array(strtolower($item->getAddress()), $addressList)) {
- throw new RuntimeException("Address list contains a duplicate.");
+ throw new InvalidArgumentException("Address list contains a duplicate.");
}
$addressList[] = strtolower($item->getAddress());
diff --git a/application/Espo/Core/Field/Link.php b/application/Espo/Core/Field/Link.php
index 916013e879..c2200ef1e8 100644
--- a/application/Espo/Core/Field/Link.php
+++ b/application/Espo/Core/Field/Link.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A link value object. Immutable.
@@ -42,7 +42,7 @@ class Link
public function __construct(string $id)
{
if (!$id) {
- throw new RuntimeException("Empty ID.");
+ throw new InvalidArgumentException("Empty ID.");
}
$this->id = $id;
diff --git a/application/Espo/Core/Field/LinkMultiple.php b/application/Espo/Core/Field/LinkMultiple.php
index 9ca96cc6ab..8bc41a5865 100644
--- a/application/Espo/Core/Field/LinkMultiple.php
+++ b/application/Espo/Core/Field/LinkMultiple.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A link-multiple value object. Immutable.
@@ -38,7 +38,7 @@ class LinkMultiple
{
/**
* @param LinkMultipleItem[] $list
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function __construct(private array $list = [])
{
@@ -148,8 +148,7 @@ class LinkMultiple
* Clone with an added item list.
* .
* @param LinkMultipleItem[] $list
- *
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function withAddedList(array $list): self
{
@@ -201,7 +200,7 @@ class LinkMultiple
*
* @param LinkMultipleItem[] $list
*
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public static function create(array $list = []): self
{
@@ -214,11 +213,11 @@ class LinkMultiple
foreach ($this->list as $item) {
if (!$item instanceof LinkMultipleItem) {
- throw new RuntimeException("Bad item.");
+ throw new InvalidArgumentException("Bad item.");
}
if (in_array($item->getId(), $idList)) {
- throw new RuntimeException("List contains duplicates.");
+ throw new InvalidArgumentException("List contains duplicates.");
}
$idList[] = strtolower($item->getId());
diff --git a/application/Espo/Core/Field/LinkMultipleItem.php b/application/Espo/Core/Field/LinkMultipleItem.php
index 75b6e397c0..92cdc267b6 100644
--- a/application/Espo/Core/Field/LinkMultipleItem.php
+++ b/application/Espo/Core/Field/LinkMultipleItem.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A link-multiple item. Immutable.
@@ -42,12 +42,12 @@ class LinkMultipleItem
private array $columnData = [];
/**
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function __construct(string $id)
{
if ($id === '') {
- throw new RuntimeException("Empty ID.");
+ throw new InvalidArgumentException("Empty ID.");
}
$this->id = $id;
@@ -124,7 +124,7 @@ class LinkMultipleItem
/**
* Create.
*
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public static function create(string $id, ?string $name = null): self
{
diff --git a/application/Espo/Core/Field/LinkParent.php b/application/Espo/Core/Field/LinkParent.php
index 0b394dd838..4f58122335 100644
--- a/application/Espo/Core/Field/LinkParent.php
+++ b/application/Espo/Core/Field/LinkParent.php
@@ -30,7 +30,7 @@
namespace Espo\Core\Field;
use Espo\ORM\Entity;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A link-parent value object. Immutable.
@@ -44,11 +44,11 @@ class LinkParent
public function __construct(string $entityType, string $id)
{
if (!$entityType) {
- throw new RuntimeException("Empty entity type.");
+ throw new InvalidArgumentException("Empty entity type.");
}
if (!$id) {
- throw new RuntimeException("Empty ID.");
+ throw new InvalidArgumentException("Empty ID.");
}
$this->entityType = $entityType;
@@ -93,6 +93,8 @@ class LinkParent
/**
* Create.
+ *
+ * @throws InvalidArgumentException
*/
public static function create(string $entityType, string $id): self
{
diff --git a/application/Espo/Core/Field/PhoneNumber.php b/application/Espo/Core/Field/PhoneNumber.php
index 25550b3c32..f9faa20ae0 100644
--- a/application/Espo/Core/Field/PhoneNumber.php
+++ b/application/Espo/Core/Field/PhoneNumber.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A phone number value. Immutable.
@@ -44,7 +44,7 @@ class PhoneNumber
public function __construct(string $number)
{
if ($number === '') {
- throw new RuntimeException("Empty phone number.");
+ throw new InvalidArgumentException("Empty phone number.");
}
$this->number = $number;
@@ -144,6 +144,8 @@ class PhoneNumber
/**
* Create with a number.
+ *
+ * @throws InvalidArgumentException
*/
public static function create(string $number): self
{
@@ -152,6 +154,8 @@ class PhoneNumber
/**
* Create from a number and type.
+ *
+ * @throws InvalidArgumentException
*/
public static function createWithType(string $number, string $type): self
{
diff --git a/application/Espo/Core/Field/PhoneNumberGroup.php b/application/Espo/Core/Field/PhoneNumberGroup.php
index 49a07ee3be..3f0ea2356b 100644
--- a/application/Espo/Core/Field/PhoneNumberGroup.php
+++ b/application/Espo/Core/Field/PhoneNumberGroup.php
@@ -29,7 +29,7 @@
namespace Espo\Core\Field;
-use RuntimeException;
+use InvalidArgumentException;
/**
* A phone number group. Contains a list of phone numbers. One phone number is set as primary.
@@ -43,8 +43,7 @@ class PhoneNumberGroup
/**
* @param PhoneNumber[] $list
- *
- * @throws RuntimeException
+ * @throws InvalidArgumentException
*/
public function __construct(array $list = [])
{
@@ -81,11 +80,8 @@ class PhoneNumberGroup
{
$primary = $this->getPrimary();
- if (!$primary) {
- return null;
- }
+ return $primary?->getNumber();
- return $primary->getNumber();
}
/**
@@ -169,7 +165,7 @@ class PhoneNumberGroup
}
/**
- * Whether an number is in the list.
+ * Whether the number is in the list.
*/
public function hasNumber(string $number): bool
{
@@ -258,6 +254,7 @@ class PhoneNumberGroup
* Create with an optional phone number list. A first item will be set as primary.
*
* @param PhoneNumber[] $list
+ * @throws InvalidArgumentException
*/
public static function create(array $list = []): self
{
@@ -281,11 +278,11 @@ class PhoneNumberGroup
foreach ($this->list as $item) {
if (!$item instanceof PhoneNumber) {
- throw new RuntimeException("Bad item.");
+ throw new InvalidArgumentException("Bad item.");
}
if (in_array($item->getNumber(), $numberList)) {
- throw new RuntimeException("Number list contains a duplicate.");
+ throw new InvalidArgumentException("Number list contains a duplicate.");
}
$numberList[] = strtolower($item->getNumber());
diff --git a/tests/unit/Espo/Core/Field/Currency/CurrencyTest.php b/tests/unit/Espo/Core/Field/Currency/CurrencyTest.php
index 9ef8d403dc..1651676dde 100644
--- a/tests/unit/Espo/Core/Field/Currency/CurrencyTest.php
+++ b/tests/unit/Espo/Core/Field/Currency/CurrencyTest.php
@@ -29,16 +29,15 @@
namespace tests\unit\Espo\Core\Field\Currency;
-use Espo\Core\{
- Field\Currency,
- Field\Currency\CurrencyFactory,
-};
+use Espo\Core\Field\Currency;
+use Espo\Core\Field\Currency\CurrencyFactory;
use Espo\ORM\Entity;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
-class CurrencyTest extends \PHPUnit\Framework\TestCase
+class CurrencyTest extends TestCase
{
public function testValue()
{
@@ -122,7 +121,7 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase
public function testBadAdd()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
(new Currency(2.0, 'USD'))->add(
new Currency(1.0, 'EUR')
@@ -131,7 +130,7 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase
public function testGetBadCode()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
new Currency(2.0, '');
}
@@ -237,7 +236,7 @@ class CurrencyTest extends \PHPUnit\Framework\TestCase
public function testCompare4(): void
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
Currency::create(2.1, 'EUR')
->compare(
diff --git a/tests/unit/Espo/Core/Field/Date/DateTest.php b/tests/unit/Espo/Core/Field/Date/DateTest.php
index 503deaf08c..e7d41bbc96 100644
--- a/tests/unit/Espo/Core/Field/Date/DateTest.php
+++ b/tests/unit/Espo/Core/Field/Date/DateTest.php
@@ -29,16 +29,15 @@
namespace tests\unit\Espo\Core\Field\Date;
-use Espo\Core\{
- Field\Date,
-};
+use Espo\Core\Field\Date;
use DateTimeImmutable;
use DateTimeZone;
-use RuntimeException;
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
use DateInterval;
-class DateTest extends \PHPUnit\Framework\TestCase
+class DateTest extends TestCase
{
public function testFromString()
{
@@ -58,21 +57,21 @@ class DateTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
Date::fromString('2021-05-A');
}
public function testBad2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
Date::fromString('2021-05-1');
}
public function testEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
Date::fromString('');
}
diff --git a/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php b/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
index 34d2df7e1a..8f3942d11a 100644
--- a/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
+++ b/tests/unit/Espo/Core/Field/DateTime/DateTimeTest.php
@@ -33,10 +33,11 @@ use Espo\Core\Field\DateTime;
use DateTimeImmutable;
use DateTimeZone;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
use DateInterval;
-class DateTimeTest extends \PHPUnit\Framework\TestCase
+class DateTimeTest extends TestCase
{
public function testFromString1()
{
@@ -72,21 +73,21 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTime::fromString('2021-05-A 10:20:30');
}
public function testBad2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTime::fromString('2021-05-1 10:20:30');
}
public function testEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTime::fromString('');
}
diff --git a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalDateTest.php b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalDateTest.php
index fde746c16b..2fe91e1342 100644
--- a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalDateTest.php
+++ b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalDateTest.php
@@ -29,16 +29,15 @@
namespace tests\unit\Espo\Core\Field\DateTimeOptional;
-use Espo\Core\{
- Field\DateTimeOptional,
-};
+use Espo\Core\Field\DateTimeOptional;
use DateTimeImmutable;
use DateTimeZone;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
use DateInterval;
-class DateTimeOptionalDateTest extends \PHPUnit\Framework\TestCase
+class DateTimeOptionalDateTest extends TestCase
{
public function testFromString()
{
@@ -60,21 +59,21 @@ class DateTimeOptionalDateTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('2021-05-A');
}
public function testBad2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('2021-05-1');
}
public function testEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('');
}
diff --git a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
index 9858390417..69e0c771db 100644
--- a/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
+++ b/tests/unit/Espo/Core/Field/DateTimeOptional/DateTimeOptionalTest.php
@@ -29,16 +29,15 @@
namespace tests\unit\Espo\Core\Field\DateTimeOptionalTest;
-use Espo\Core\{
- Field\DateTime,
- Field\DateTimeOptional};
+use Espo\Core\Field\DateTimeOptional;
use DateTimeImmutable;
use DateTimeZone;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
use DateInterval;
-class DateTimeOptionalTest extends \PHPUnit\Framework\TestCase
+class DateTimeOptionalTest extends TestCase
{
public function testFromString1()
{
@@ -78,21 +77,21 @@ class DateTimeOptionalTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('2021-05-A 10:20:30');
}
public function testBad2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('2021-05-1 10:20:30');
}
public function testEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
DateTimeOptional::fromString('');
}
diff --git a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupAttributeExtractorTest.php b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupAttributeExtractorTest.php
index 019530dcf5..43e000b528 100644
--- a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupAttributeExtractorTest.php
+++ b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupAttributeExtractorTest.php
@@ -29,13 +29,12 @@
namespace tests\unit\Espo\Core\Field\EmailAddress;
-use Espo\Core\{
- Field\EmailAddress,
- Field\EmailAddressGroup,
- Field\EmailAddress\EmailAddressGroupAttributeExtractor,
-};
+use Espo\Core\Field\EmailAddress;
+use Espo\Core\Field\EmailAddress\EmailAddressGroupAttributeExtractor;
+use Espo\Core\Field\EmailAddressGroup;
+use PHPUnit\Framework\TestCase;
-class EmailAddressGroupAttributeExtractorTest extends \PHPUnit\Framework\TestCase
+class EmailAddressGroupAttributeExtractorTest extends TestCase
{
public function testExtract()
{
diff --git a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupTest.php b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupTest.php
index 86834510d4..4ae291c94d 100644
--- a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupTest.php
+++ b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressGroupTest.php
@@ -29,14 +29,13 @@
namespace tests\unit\Espo\Core\Field\EmailAddress;
-use Espo\Core\{
- Field\EmailAddress,
- Field\EmailAddressGroup,
-};
+use Espo\Core\Field\EmailAddress;
+use Espo\Core\Field\EmailAddressGroup;
-use RuntimeException;
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
-class EmailAddressGroupTest extends \PHPUnit\Framework\TestCase
+class EmailAddressGroupTest extends TestCase
{
public function testEmpty()
{
@@ -53,7 +52,7 @@ class EmailAddressGroupTest extends \PHPUnit\Framework\TestCase
public function testDuplicate1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
EmailAddressGroup
::create([
@@ -64,7 +63,7 @@ class EmailAddressGroupTest extends \PHPUnit\Framework\TestCase
public function testDuplicate2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
EmailAddressGroup
::create([
diff --git a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressTest.php b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressTest.php
index 9b321648c5..937ac68af6 100644
--- a/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressTest.php
+++ b/tests/unit/Espo/Core/Field/EmailAddress/EmailAddressTest.php
@@ -29,24 +29,23 @@
namespace tests\unit\Espo\Core\Field\EmailAddress;
-use Espo\Core\{
- Field\EmailAddress,
-};
+use Espo\Core\Field\EmailAddress;
-use RuntimeException;
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
-class EmailAddressTest extends \PHPUnit\Framework\TestCase
+class EmailAddressTest extends TestCase
{
public function testInvalidAddress()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
EmailAddress::create('one');
}
public function testInvalidEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
EmailAddress::create('');
}
diff --git a/tests/unit/Espo/Core/Field/Link/LinkTest.php b/tests/unit/Espo/Core/Field/Link/LinkTest.php
index e76d57a7db..6faf14cd28 100644
--- a/tests/unit/Espo/Core/Field/Link/LinkTest.php
+++ b/tests/unit/Espo/Core/Field/Link/LinkTest.php
@@ -29,13 +29,12 @@
namespace tests\unit\Espo\Core\Field\Link;
-use Espo\Core\{
- Field\Link,
-};
+use Espo\Core\Field\Link;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
-class LinkTest extends \PHPUnit\Framework\TestCase
+class LinkTest extends TestCase
{
public function testCreate()
{
@@ -47,7 +46,7 @@ class LinkTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
Link::create('');
}
diff --git a/tests/unit/Espo/Core/Field/LinkMultiple/LinkMultipleTest.php b/tests/unit/Espo/Core/Field/LinkMultiple/LinkMultipleTest.php
index 12ae2faf90..35ff2f056a 100644
--- a/tests/unit/Espo/Core/Field/LinkMultiple/LinkMultipleTest.php
+++ b/tests/unit/Espo/Core/Field/LinkMultiple/LinkMultipleTest.php
@@ -32,9 +32,10 @@ namespace tests\unit\Espo\Core\Field\LinkMultiple;
use Espo\Core\Field\LinkMultiple;
use Espo\Core\Field\LinkMultipleItem;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
-class LinkMultipleTest extends \PHPUnit\Framework\TestCase
+class LinkMultipleTest extends TestCase
{
public function testEmpty()
{
@@ -47,7 +48,7 @@ class LinkMultipleTest extends \PHPUnit\Framework\TestCase
public function testDuplicate()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
LinkMultiple
::create([
diff --git a/tests/unit/Espo/Core/Field/LinkParent/LinkParentTest.php b/tests/unit/Espo/Core/Field/LinkParent/LinkParentTest.php
index 70716695ca..76f2a7851c 100644
--- a/tests/unit/Espo/Core/Field/LinkParent/LinkParentTest.php
+++ b/tests/unit/Espo/Core/Field/LinkParent/LinkParentTest.php
@@ -29,13 +29,12 @@
namespace tests\unit\Espo\Core\Field\LinkParent;
-use Espo\Core\{
- Field\LinkParent,
-};
+use Espo\Core\Field\LinkParent;
-use RuntimeException;
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
-class LinkParentTest extends \PHPUnit\Framework\TestCase
+class LinkParentTest extends TestCase
{
public function testCreate()
{
@@ -48,14 +47,14 @@ class LinkParentTest extends \PHPUnit\Framework\TestCase
public function testBad1()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
LinkParent::create('Test', '');
}
public function testBad2()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
LinkParent::create('', 'id');
}
diff --git a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupAttributeExtractorTest.php b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupAttributeExtractorTest.php
index 08ba8bf238..107b67c51b 100644
--- a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupAttributeExtractorTest.php
+++ b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupAttributeExtractorTest.php
@@ -29,13 +29,12 @@
namespace tests\unit\Espo\Core\Field\PhoneNumber;
-use Espo\Core\{
- Field\PhoneNumber,
- Field\PhoneNumberGroup,
- Field\PhoneNumber\PhoneNumberGroupAttributeExtractor,
-};
+use Espo\Core\Field\PhoneNumber;
+use Espo\Core\Field\PhoneNumber\PhoneNumberGroupAttributeExtractor;
+use Espo\Core\Field\PhoneNumberGroup;
+use PHPUnit\Framework\TestCase;
-class PhoneNumberGroupAttributeExtractorTest extends \PHPUnit\Framework\TestCase
+class PhoneNumberGroupAttributeExtractorTest extends TestCase
{
public function testExtract()
{
diff --git a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php
index 685f454588..e4b01ced2f 100644
--- a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php
+++ b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupFactoryTest.php
@@ -29,21 +29,19 @@
namespace tests\unit\Espo\Core\Field\PhoneNumber;
-use Espo\Core\{
- Field\PhoneNumber\PhoneNumberGroupFactory,
- Utils\Metadata,
-};
+use Espo\Core\Field\PhoneNumber\PhoneNumberGroupFactory;
+use Espo\Core\Utils\Metadata;
-use Espo\ORM\{
- EntityManager,
- Entity,
-};
+use Espo\ORM\Entity;
+use Espo\ORM\EntityManager;
use Espo\Repositories\PhoneNumber as PhoneNumberRepository;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
use RuntimeException;
-class PhoneNumberGroupFactoryTest extends \PHPUnit\Framework\TestCase
+class PhoneNumberGroupFactoryTest extends TestCase
{
/**
* @var Metadata
diff --git a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupTest.php b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupTest.php
index 4d13ba857e..1dc8148982 100644
--- a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupTest.php
+++ b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberGroupTest.php
@@ -29,14 +29,13 @@
namespace tests\unit\Espo\Core\Field\PhoneNumber;
-use Espo\Core\{
- Field\PhoneNumber,
- Field\PhoneNumberGroup,
-};
+use Espo\Core\Field\PhoneNumber;
+use Espo\Core\Field\PhoneNumberGroup;
-use RuntimeException;
+use PHPUnit\Framework\TestCase;
+use InvalidArgumentException;
-class PhoneNumberGroupTest extends \PHPUnit\Framework\TestCase
+class PhoneNumberGroupTest extends TestCase
{
public function testEmpty()
{
@@ -53,7 +52,7 @@ class PhoneNumberGroupTest extends \PHPUnit\Framework\TestCase
public function testDuplicate()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
PhoneNumberGroup
::create([
diff --git a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberTest.php b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberTest.php
index 2981ff57ff..73ce88a8f0 100644
--- a/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberTest.php
+++ b/tests/unit/Espo/Core/Field/PhoneNumber/PhoneNumberTest.php
@@ -29,17 +29,16 @@
namespace tests\unit\Espo\Core\Field\PhoneNumber;
-use Espo\Core\{
- Field\PhoneNumber,
-};
+use Espo\Core\Field\PhoneNumber;
-use RuntimeException;
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
-class PhoneNumberTest extends \PHPUnit\Framework\TestCase
+class PhoneNumberTest extends TestCase
{
public function testInvalidEmpty()
{
- $this->expectException(RuntimeException::class);
+ $this->expectException(InvalidArgumentException::class);
PhoneNumber::create('');
}