Ich weiß nicht, wie ich von at () zu einmal () in Phpunit 10 und höher wechseln sollPhp

PHP-Programmierer chatten hier
Anonymous
 Ich weiß nicht, wie ich von at () zu einmal () in Phpunit 10 und höher wechseln soll

Post by Anonymous »

Die Methodenfunktion at () wurde später von Phpunit 10 entfernt.

Code: Select all

...
/**
* KernelEvents::REQUEST => 'onRequest'
*/
public function onRequest(RequestEvent $event) {
...
$termStorage = $this->entityTypeManager->getStorage('taxonomy_term');
$query = $termStorage->getQuery()
->condition('vid', $vocabulary_id)
->condition('name', $name);
$termIds = $query->execute();
....
...
< /code>
Unittest Code: < /p>
...
public function testOnRequest() {
...
$query = $this->createMock(QueryInterface::class);
$query->expects($this->once())
->method('condition')
->with('vid', 'test_tags')
->willReturnSelf();
$query->expects($this->once())
->method('condition')
->with('name', 'Existing Tag')
->willReturnSelf();
$query->expects($this->once())
->method('execute')
->willReturn([123]);

$termStorage = $this->createMock(EntityStorageInterface::class);
$termStorage->expects($this->once())
->method('getQuery')
->willReturn($query);

$this->entityTypeManager->expects($this->once())
->method('getStorage')
->with('taxonomy_term')
->willReturn($termStorage);
...
}
...
< /code>
Führen Sie Phpunit aus: < /p>
...
Expectation failed for method name is "condition" when invoked 1 time
Parameter 0 for invocation Drupal\Core\Entity\Query\QueryInterface::condition('vid', 'test_tags', null, null) does not match expected value.
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'name'
+'vid'
...
Wie schreibe ich Testcode?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post