Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- HTML
- post
- date
- 경영
- curl
- string
- MySQL
- composer-php
- Apache
- php
- Arrays
- Ajax
- UTF-8
- 전략
- Laravel
- 웹하드순위
- JSON
- Linux
- OOP
- 웹하드추천
- 무료다운로드쿠폰
- function
- variables
- file-upload
- Regex
- Session
- JavaScript
- Forms
- jquery
Archives
- Today
- Total
개발! 딱 깔끔하고 센스있게!
PHP 유닛 "Mocked method" 가 존재 하지 않 습 니 다. $mock - > expects ($this - > at (...) 를 사용 할 때, 본문
개발 스크랩 메모/PHP
PHP 유닛 "Mocked method" 가 존재 하지 않 습 니 다. $mock - > expects ($this - > at (...) 를 사용 할 때,
렉사이 2020. 12. 2. 22:39나 는 PHP 유닛 모 의 대상 에 대한 이상 한 질문 을 받 았 다.
나 는 두 번 이나 호출 해 야 하 는 방법 이 있어 서 '잇' 매 칭 기 를 사용 합 니 다.
이것 은 첫 번 째 호출 방법 이지 만 어떤 이유 로 두 번 째 호출 할 때 저 는 'Mocked method' 를 얻 었 습 니 다.
나 는 이전에 성냥 개비 로 이런 상황 을 만난 적 이 없다.
제 코드 는 다음 과 같 습 니 다.
class MyTest extends PHPUnit_Framework_TestCase { ... public function testThis() { $mock = $this->getMock('MyClass', array('exists', 'another_method', '...')); $mock->expects($this->at(0)) ->method('exists') ->with($this->equalTo('foo')) ->will($this->returnValue(true)); $mock->expects($this->at(1)) ->method('exists') ->with($this->equalTo('bar')) ->will($this->returnValue(false)); } ... }
내 가 테스트 를 실행 할 때, 나 는 얻 은 것:
Expectation failed for method name is equal to when invoked at sequence index 1. Mocked method does not exist.
내 가 두 번 째 매 칭 기 를 지 웠 다 면, 나 는 잘못 을 받 지 않 았 을 것 이다.
혹시 이거 본 사람 있어 요?
감사합니다.
대답 하 다.
마지막 문 제 는 제 가 어떻게 '잇' 매 칭 기 작업 을 이해 하 느 냐 입 니 다.
한편, 나의 예 는 단원 테스트 중의 상황 을 한 글자 한 마디 한 마디 로 서술 하지 않 았 다.
나 는 "at" matcher 카운터 가 모든 조 회 를 바탕 으로 하 는 인 스 턴 스 라 고 생각한다.
실제로 모든 개체 의 기초 위 에서 일 하 는 것 이다.
보기:
class MyClass { public function exists($foo) { return false; } public function find($foo) { return $foo; } }
부정 확:
class MyTest extends PHPUnit_Framework_TestCase { public function testThis() { $mock = $this->getMock('MyClass'); $mock->expects($this->at(0)) ->method('exists') ->with($this->equalTo('foo')) ->will($this->returnValue(true)); $mock->expects($this->at(0)) ->method('find') ->with($this->equalTo('foo')) ->will($this->returnValue('foo')); $mock->expects($this->at(1)) ->method('exists') ->with($this->equalTo('bar')) ->will($this->returnValue(false)); $this->assertTrue($mock->exists("foo")); $this->assertEquals('foo', $mock->find('foo')); $this->assertFalse($mock->exists("bar")); } }
맞습니다:
class MyTest extends PHPUnit_Framework_TestCase { public function testThis() { $mock = $this->getMock('MyClass'); $mock->expects($this->at(0)) ->method('exists') ->with($this->equalTo('foo')) ->will($this->returnValue(true)); $mock->expects($this->at(1)) ->method('find') ->with($this->equalTo('foo')) ->will($this->returnValue('foo')); $mock->expects($this->at(2)) ->method('exists') ->with($this->equalTo('bar')) ->will($this->returnValue(false)); $this->assertTrue($mock->exists("foo")); $this->assertEquals('foo', $mock->find('foo')); $this->assertFalse($mock->exists("bar")); } }
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
Laravel 세 션 은 로 컬 PHP 에서 사용 할 수 없습니다? (0) | 2020.12.02 |
---|---|
PHP 는 사용자 이름 이 X 인 데이터베이스 에서 필드 를 선택 합 니 다. (0) | 2020.12.02 |
XML 데 이 터 를 PHP 변수 로 분석 하 는 방법 (0) | 2020.12.02 |
PHP 로 만 든 트랙 과 맞 먹 는 것 이 있 습 니까?[종료] (0) | 2020.12.02 |
PHP Mailer 와 GMAIL SMTP 를 사용 하여 메 일 을 보 냅 니 다. (0) | 2020.12.02 |
Comments