Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
"guzzlehttp/guzzle": "^7.9",
"nette/di": "^3.1.10",
"nette/utils": "^4.0.0|^3.2.5",
"symfony/console": "^7.0.2",
"tracy/tracy": "^2.6.7",
"symfony/console": "^7.0.3",
"tracy/tracy": "^2.9",
"monolog/monolog": "^3.0.0",
"ezimuel/ringphp": "^1.2"
},
"require-dev": {
"slevomat/coding-standard": "^8.15.0",
"spameri/dependency-mocker": "^1.3",
"nette/tester": "^v2.5.7",
"phpstan/phpstan": "^1.11.3",
"phpstan/phpstan": "^1.11.10",
"php-coveralls/php-coveralls": "^2.1",
"nette/bootstrap": "^3.1",
"nette/http": "^3.0.7",
Expand All @@ -67,5 +67,11 @@
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"conflict": {
"nette/neon": "<3.3.4 || >=3.4.0 <3.4.4",
"symfony/string": "<6.4.3 || >=7.0 <7.0.3",
"psr/http-factory": "<1.1",
"symfony/polyfill-mbstring": "<1.3"
}
}
5 changes: 0 additions & 5 deletions phpstan-low.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ parameters:
- %rootDir%/../../../phpstanConstants.php

ignoreErrors:
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/Factory/EntityFactory.php

-
message: "#^Variable \\$propertyValue might not be defined\\.$#"
count: 1
Expand Down
3 changes: 3 additions & 0 deletions src/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public function persist(
$this->dispatchEvents->execute($entity, EventManager::POST_CREATE);
$this->dispatchEvents->execute($entity, EventManager::POST_PERSIST);

// The entity is stored now: a second persist of this instance is an update, not a create.
$this->changeSet->markExisting($entity);

return $id;
}

Expand Down
40 changes: 40 additions & 0 deletions tests/SpameriTests/Elastic/EntityManager/PersistTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,46 @@ class PersistTest extends \SpameriTests\Elastic\AbstractTestCase
}


public function testSecondPersistOfSameInstanceFiresPostUpdate(): void
{
$createListener = new \SpameriTests\Elastic\Data\Listener\MockListener(
[\SpameriTests\Elastic\Data\Entity\Title::class],
\Spameri\Elastic\EventManager::POST_CREATE,
);
$updateListener = new \SpameriTests\Elastic\Data\Listener\MockListener(
[\SpameriTests\Elastic\Data\Entity\Title::class],
\Spameri\Elastic\EventManager::POST_UPDATE,
);

/** @var \Spameri\Elastic\EventManager $eventManager */
$eventManager = $this->container->getByType(\Spameri\Elastic\EventManager::class);
$eventManager->addListener(
\Spameri\Elastic\EventManager::POST_CREATE,
\SpameriTests\Elastic\Data\Entity\Title::class,
$createListener,
);
$eventManager->addListener(
\Spameri\Elastic\EventManager::POST_UPDATE,
\SpameriTests\Elastic\Data\Entity\Title::class,
$updateListener,
);

/** @var \Spameri\Elastic\EntityManager $entityManager */
$entityManager = $this->container->getByType(\Spameri\Elastic\EntityManager::class);

$entity = new \SpameriTests\Elastic\Data\Entity\Title(
new \Spameri\Elastic\Entity\Property\EmptyElasticId(),
null,
);

$entityManager->persist($entity);
$entityManager->persist($entity);

\Tester\Assert::same(1, $createListener->getCallCount());
\Tester\Assert::same(1, $updateListener->getCallCount());
}


public function testPersistReturnsIdString(): void
{
/** @var \Spameri\Elastic\EntityManager $entityManager */
Expand Down
3 changes: 3 additions & 0 deletions tests/SpameriTests/Elastic/Model/DumpIndex/Execute.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Execute extends \SpameriTests\Elastic\AbstractTestCase
$restoreIndex->setOutput(new \Symfony\Component\Console\Output\ConsoleOutput());

$restoreIndex->execute(__DIR__ . '/dumpData.json', 500);

// The dump reads through search, which only sees documents after a refresh.
$clientProvider->client()->indices()->refresh(['index' => \SpameriTests\Elastic\Config::INDEX_DUMP]);
}


Expand Down
Loading