/** * @test * @author Christopher Hlubek <*****@*****.**> */ public function synchronizeWithNoDesignDocumentCollectsDeclarationsAndCreatesDesignDocument() { $mockReflectionService = $this->getMock('TYPO3\\Flow\\Reflection\\ReflectionService'); $design = new Fixtures\Design\CompanyDesign(); $design->setClient($this->client); $design->injectReflectionService($mockReflectionService); $mockReflectionService->expects($this->any())->method('isMethodStatic')->will($this->returnCallback(function ($className, $methodName) { if ($methodName === 'totalPurchasesDeclaration') { return TRUE; } return FALSE; })); $this->client->expects($this->any())->method('getDocument')->with('_design/company')->will($this->throwException(new \TYPO3\CouchDB\Client\NotFoundException('{"error":"not_found","reason":"missing"}'))); $this->client->expects($this->once())->method('createDocument')->with(array('_id' => '_design/company', 'language' => 'javascript', 'views' => array('totalPurchases' => array('map' => 'function(doc) { if (doc.Type == "purchase") { emit(doc.Customer, doc.Amount); } }', 'reduce' => 'function(keys, values) { return sum(values) }')))); $design->synchronize(); }
/** * @test * @author Christopher Hlubek <*****@*****.**> */ public function callingViewReturnsResult() { $design = new Fixtures\Design\CompanyDesign(); $design->setClient($this->client); $design->synchronize(); for ($i = 0; $i < 10; $i++) { $this->client->createDocument(array('Type' => 'purchase', 'Customer' => '12345678', 'Amount' => 13.95 * ($i + 1))); } $result = $design->totalPurchasesAmount('12345678'); $this->assertEquals(767.25, $result); }