44 $this->connection = $this->createPartialMock(
45 \
Magento\Framework\DB\Adapter\Pdo\Mysql::class,
46 [
'select',
'insertOnDuplicate',
'fetchRow']
48 $this->resource = $this->createMock(\
Magento\Framework\
App\ResourceConnection::class);
49 $this->logFactory = $this->createPartialMock(\
Magento\
Customer\Model\LogFactory::class, [
'create']);
51 $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
53 $this->logger = $objectManagerHelper->getObject(
56 'resource' => $this->resource,
57 'logFactory' => $this->logFactory
74 $this->expectException(
'\InvalidArgumentException');
75 $this->expectExceptionMessage(
'Log data is empty');
80 $this->resource->expects($this->once())
81 ->method(
'getConnection')
82 ->willReturn($this->connection);
83 $this->resource->expects($this->once())
84 ->method(
'getTableName')
85 ->with(
'customer_log')
87 $this->connection->expects($this->once())
88 ->method(
'insertOnDuplicate')
100 [235, [
'last_login_at' =>
'2015-03-04 12:00:00']],
101 [235, [
'last_login_at' =>
null]],
114 'customerId' =>
$data[
'customer_id'],
115 'lastLoginAt' =>
$data[
'last_login_at'],
116 'lastLogoutAt' =>
$data[
'last_logout_at'],
117 'lastVisitAt' =>
$data[
'last_visit_at']
122 $select->expects($this->any())->method(
'from')->willReturnSelf();
123 $select->expects($this->any())->method(
'joinLeft')->willReturnSelf();
124 $select->expects($this->any())->method(
'where')->willReturnSelf();
125 $select->expects($this->any())->method(
'order')->willReturnSelf();
126 $select->expects($this->any())->method(
'limit')->willReturnSelf();
128 $this->connection->expects($this->any())
132 $this->resource->expects($this->once())
133 ->method(
'getConnection')
134 ->willReturn($this->connection);
135 $this->connection->expects($this->any())
141 ->setConstructorArgs($logArguments)
144 $this->logFactory->expects($this->any())
146 ->with($logArguments)
149 $this->assertEquals($log, $this->logger->get(
$customerId));
161 'customer_id' => 369,
162 'last_login_at' =>
'2015-03-04 12:00:00',
163 'last_visit_at' =>
'2015-03-04 12:01:00',
164 'last_logout_at' =>
'2015-03-04 12:05:00',
170 'customer_id' => 369,
171 'last_login_at' =>
'2015-03-04 12:00:00',
172 'last_visit_at' =>
'2015-03-04 12:01:00',
173 'last_logout_at' =>
null,
179 'customer_id' =>
null,
180 'last_login_at' =>
null,
181 'last_visit_at' =>
null,
182 'last_logout_at' =>
null,
testLog($customerId, $data)
testGet($customerId, $data)