diff --git a/lib/Models/Model.php b/lib/Models/Model.php index 228c5f115d..d5c06ffb1f 100644 --- a/lib/Models/Model.php +++ b/lib/Models/Model.php @@ -232,7 +232,7 @@ class Model extends \MailPoetVendor\Sudzy\ValidModel { } catch (\PDOException $e) { switch ($e->getCode()) { case 23000: - preg_match("/for key \'(.*?)\'/i", $e->getMessage(), $matches); + preg_match("/for key '(?:.*\.)*(.*?)'/i", $e->getMessage(), $matches); if (isset($matches[1])) { $column = $matches[1]; $this->setError( diff --git a/tests/integration/API/JSON/v1/SegmentsTest.php b/tests/integration/API/JSON/v1/SegmentsTest.php index 02d0b39f4c..faca941d91 100644 --- a/tests/integration/API/JSON/v1/SegmentsTest.php +++ b/tests/integration/API/JSON/v1/SegmentsTest.php @@ -79,7 +79,7 @@ class SegmentsTest extends \MailPoetTest { $response = $this->endpoint->save($duplicateEntry); expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST); - expect($response->errors[0]['message'])->regExp('/Another record already exists. Please specify a different ".*name"./'); + expect($response->errors[0]['message'])->equals('Another record already exists. Please specify a different "name".'); } public function testItCanRestoreASegment() { diff --git a/tests/integration/DynamicSegments/Persistence/SaverTest.php b/tests/integration/DynamicSegments/Persistence/SaverTest.php index 5cc0f8e461..aa32de6f97 100644 --- a/tests/integration/DynamicSegments/Persistence/SaverTest.php +++ b/tests/integration/DynamicSegments/Persistence/SaverTest.php @@ -49,6 +49,7 @@ class SaverTest extends \MailPoetTest { ]); $this->expectException('\MailPoet\DynamicSegments\Exceptions\ErrorSavingException'); $this->expectExceptionCode(Model::DUPLICATE_RECORD); + $this->expectExceptionMessage('Another record already exists. Please specify a different "PRIMARY".'); $this->saver->save($dynamicSegment2); }