Я не знаю, как измениться с at () на один () в Phpunit 10 и вышеPhp

Кемеровские программисты php общаются здесь
Ответить
Anonymous
 Я не знаю, как измениться с at () на один () в Phpunit 10 и выше

Сообщение Anonymous »

Функция метода at () была удалена из PhpUnit 10 позже.
Я изменил AT () на one () , но мои тесты все еще не проходят
Тест не удается, потому что вы не можете упорядочить вызовы условия ().

Код: Выделить всё

...
/**
* 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: < /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>
запустить phpunit: < /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'
...
Как мне написать тестовый код?

Подробнее здесь: https://stackoverflow.com/questions/795 ... -and-above
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Php»