コード例 #1
0
 /**
  * Test all events.
  */
 public function testAll()
 {
     for ($i = 1; $i <= 11; ++$i) {
         $this->current_timestamp->addSecond();
         DateTimeValue::setTestNow($this->current_timestamp);
         $this->account->events->add("Event {$i}");
     }
     $all_events = $this->account->events->all();
     $this->assertCount(11, $all_events);
     $this->assertEquals('Event 11', $all_events[0]['name']);
     $this->assertEquals('Event 1', $all_events[10]['name']);
 }
コード例 #2
0
ファイル: ArpuTest.php プロジェクト: activecollab/insight
 /**
  * Test ARPU on day call.
  */
 public function testArpuOnDay()
 {
     $m_monthly_mrr = (new PlanM())->getMrrValue(new Monthly());
     $l_monthly_mrr = (new PlanL())->getMrrValue(new Monthly());
     $l_yearly_mrr = (new PlanL())->getMrrValue(new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-01-12');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addPaid(1, new PlanM(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-13');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addPaid(2, new PlanM(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-14');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addPaid(3, new PlanL(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-15');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addPaid(4, new PlanL(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-16');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->cancel(1);
     $this->insight->accounts->cancel(2);
     $this->current_timestamp = new DateTimeValue('2016-01-18');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(4, new PlanL(), new Yearly());
     $this->assertEquals(0, $this->insight->accounts->countPaid(new DateValue('2016-01-11')));
     $this->assertEquals(0, $this->insight->arpu->getOnDay(new DateValue('2016-01-11')));
     $this->assertEquals(1, $this->insight->accounts->countPaid(new DateValue('2016-01-12')));
     $this->assertEquals($m_monthly_mrr, $this->insight->arpu->getOnDay(new DateValue('2016-01-12')));
     $this->assertEquals(2, $this->insight->accounts->countPaid(new DateValue('2016-01-13')));
     $this->assertEquals($m_monthly_mrr, $this->insight->arpu->getOnDay(new DateValue('2016-01-13')));
     $this->assertEquals(3, $this->insight->accounts->countPaid(new DateValue('2016-01-14')));
     $this->assertEquals(ceil(($m_monthly_mrr * 2 + $l_monthly_mrr) / 3), $this->insight->arpu->getOnDay(new DateValue('2016-01-14')));
     $this->assertEquals(4, $this->insight->accounts->countPaid(new DateValue('2016-01-15')));
     $this->assertEquals(ceil(($m_monthly_mrr * 2 + $l_monthly_mrr * 2) / 4), $this->insight->arpu->getOnDay(new DateValue('2016-01-15')));
     $this->assertEquals(4, $this->insight->accounts->countPaid(new DateValue('2016-01-16')));
     $this->assertEquals(ceil(($m_monthly_mrr * 2 + $l_monthly_mrr * 2) / 4), $this->insight->arpu->getOnDay(new DateValue('2016-01-16')));
     $this->assertEquals(2, $this->insight->accounts->countPaid(new DateValue('2016-01-17')));
     $this->assertEquals($l_monthly_mrr, $this->insight->arpu->getOnDay(new DateValue('2016-01-17')));
     $this->assertEquals(2, $this->insight->accounts->countPaid(new DateValue('2016-01-18')));
     $this->assertEquals(ceil(($l_monthly_mrr + $l_yearly_mrr) / 2), $this->insight->arpu->getOnDay(new DateValue('2016-01-18')));
     // A year in the future...
     $this->assertEquals(2, $this->insight->accounts->countPaid(new DateValue('2017-01-18')));
     $this->assertEquals(ceil(($l_monthly_mrr + $l_yearly_mrr) / 2), $this->insight->arpu->getOnDay(new DateValue('2017-01-18')));
 }
コード例 #3
0
ファイル: MrrTest.php プロジェクト: activecollab/insight
 /**
  * Test MRR on day call.
  */
 public function testMrrOnDay()
 {
     $this->current_timestamp = new DateTimeValue('2016-01-12 11:11:11');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addTrial(1);
     $this->insight->accounts->addTrial(2);
     $this->insight->accounts->addTrial(3);
     $this->current_timestamp = new DateTimeValue('2016-01-15 12:12:12');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new FreePlan(), new None());
     $this->insight->accounts->changePlan(3, new PlanM(), new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-01-16 13:13:13');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanL(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-17 14:14:14');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(3, new PlanL(), new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-01-17 14:14:15');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(3, new PlanL(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-17 14:14:16');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(3, new PlanM(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-18 15:15:15');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->cancel(1);
     $m_monthly_mrr = (int) ceil((new PlanM())->getMrrValue(new Monthly()));
     $m_yearly_mrr = (int) ceil((new PlanM())->getMrrValue(new Yearly()));
     $l_monthly_mrr = (int) ceil((new PlanL())->getMrrValue(new Monthly()));
     $this->assertEquals(0, $this->insight->mrr->getOnDay(new DateValue('2016-01-12')));
     $this->assertEquals(0, $this->insight->mrr->getOnDay(new DateValue('2016-01-13')));
     $this->assertEquals(0, $this->insight->mrr->getOnDay(new DateValue('2016-01-14')));
     // Account #3, M yearly
     $this->assertSame($m_yearly_mrr, $this->insight->mrr->getOnDay(new DateValue('2016-01-15')));
     // Account #3, M yearly + Account #1, L monthly
     $this->assertEquals($m_yearly_mrr + $l_monthly_mrr, $this->insight->mrr->getOnDay(new DateValue('2016-01-16')));
     // Account #3, M monthly + Account #1, L monthly
     $this->assertEquals($m_monthly_mrr + $l_monthly_mrr, $this->insight->mrr->getOnDay(new DateValue('2016-01-17')));
     // Account #3, M monthly + Account #1, L monthly (canceled, but day started with this value)
     $this->assertEquals($m_monthly_mrr + $l_monthly_mrr, $this->insight->mrr->getOnDay(new DateValue('2016-01-18')));
     // Account #3, M monthly
     $this->assertEquals($m_monthly_mrr, $this->insight->mrr->getOnDay(new DateValue('2016-01-19')));
 }
コード例 #4
0
 /**
  * Test account status timeline.
  */
 public function testAccountStatusTimeline()
 {
     $account_status_spans_table = $this->insight->getTableName('account_status_spans');
     $this->assertEquals(0, $this->connection->count($account_status_spans_table));
     $this->current_timestamp = new DateTimeValue('2016-01-12 11:11:11');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addTrial(1);
     $this->current_timestamp = new DateTimeValue('2016-01-14 12:12:12');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new FreePlan(), new None());
     $this->current_timestamp = new DateTimeValue('2016-01-18 13:13:13');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanM(), new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-01-24 14:14:14');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->retire(1);
     $this->current_timestamp = new DateTimeValue('2016-01-28 15:15:15');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->cancel(1);
     $this->assertEquals(5, $this->connection->count($account_status_spans_table));
     $timeline = $this->insight->account(1)->status_timeline->get();
     $this->assertInternalType('array', $timeline);
     $this->assertCount(5, $timeline);
     $this->assertEquals(AccountsInterface::CANCELED, $timeline[0]['status']);
     $this->assertEquals('2016-01-28 15:15:15', $timeline[0]['started_at']->format('Y-m-d H:i:s'));
     $this->assertNull($timeline[0]['ended_at']);
     $this->assertEquals(AccountsInterface::RETIRED, $timeline[1]['status']);
     $this->assertEquals('2016-01-24 14:14:14', $timeline[1]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-28 15:15:15', $timeline[1]['ended_at']->format('Y-m-d H:i:s'));
     $this->assertEquals(AccountsInterface::PAID, $timeline[2]['status']);
     $this->assertEquals('2016-01-18 13:13:13', $timeline[2]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-24 14:14:14', $timeline[2]['ended_at']->format('Y-m-d H:i:s'));
     $this->assertEquals(AccountsInterface::FREE, $timeline[3]['status']);
     $this->assertEquals('2016-01-14 12:12:12', $timeline[3]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-18 13:13:13', $timeline[3]['ended_at']->format('Y-m-d H:i:s'));
     $this->assertEquals(AccountsInterface::TRIAL, $timeline[4]['status']);
     $this->assertEquals('2016-01-12 11:11:11', $timeline[4]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-14 12:12:12', $timeline[4]['ended_at']->format('Y-m-d H:i:s'));
 }
コード例 #5
0
 /**
  * Test account MRR timeline.
  */
 public function testAccountMrrTimeline()
 {
     $account_mrr_spans_table = $this->insight->getTableName('account_mrr_spans');
     $this->assertEquals(0, $this->connection->count($account_mrr_spans_table));
     $this->current_timestamp = new DateTimeValue('2016-01-12 11:11:11');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addTrial(1);
     $this->current_timestamp = new DateTimeValue('2016-01-14 12:12:12');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new FreePlan(), new None());
     $this->current_timestamp = new DateTimeValue('2016-01-18 13:13:13');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanM(), new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-01-24 14:14:14');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanL(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-01-27 15:15:15');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->retire(1);
     $this->current_timestamp = new DateTimeValue('2016-02-02 16:16:16');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanM(), new Monthly());
     $this->current_timestamp = new DateTimeValue('2016-07-22 17:17:17');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->cancel(1);
     $this->assertEquals(3, $this->connection->count($account_mrr_spans_table));
     $timeline = $this->insight->account(1)->mrr_timeline->get();
     $this->assertInternalType('array', $timeline);
     $this->assertCount(3, $timeline);
     $this->assertSame(49.0, $timeline[0]['mrr_value']);
     $this->assertEquals('2016-02-02 16:16:16', $timeline[0]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-07-22 17:17:17', $timeline[0]['ended_at']->format('Y-m-d H:i:s'));
     $this->assertSame(99.0, $timeline[1]['mrr_value']);
     $this->assertEquals('2016-01-24 14:14:14', $timeline[1]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-27 15:15:15', $timeline[1]['ended_at']->format('Y-m-d H:i:s'));
     $this->assertSame(41.583, $timeline[2]['mrr_value']);
     $this->assertEquals('2016-01-18 13:13:13', $timeline[2]['started_at']->format('Y-m-d H:i:s'));
     $this->assertEquals('2016-01-24 14:14:14', $timeline[2]['ended_at']->format('Y-m-d H:i:s'));
 }
コード例 #6
0
 /**
  * Test if created at timestamp is properly recorded on different events.
  */
 public function testCreationTimestampIsRecorded()
 {
     $account_updates_table = $this->insight->getTableName('account_updates');
     $this->current_timestamp = new DateTimeValue('2016-01-12 11:11:11');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->addTrial(1);
     $this->current_timestamp = new DateTimeValue('2016-01-28 12:12:12');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new PlanM(), new Yearly());
     $this->current_timestamp = new DateTimeValue('2016-02-22 13:13:13');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->changePlan(1, new FreePlan(), new None());
     $this->current_timestamp = new DateTimeValue('2016-03-12 14:14:14');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->insight->accounts->retire(1);
     /** @var DateTimeValue $first_update_timestamp */
     $first_update_timestamp = $this->connection->executeFirstCell("SELECT `created_at` FROM `{$account_updates_table}` WHERE `id` = ?", 1);
     $this->assertInstanceOf(DateTimeValue::class, $first_update_timestamp);
     $this->assertEquals('2016-01-28 12:12:12', $first_update_timestamp->format('Y-m-d H:i:s'));
     /** @var DateTimeValue $second_update_timestamp */
     $second_update_timestamp = $this->connection->executeFirstCell("SELECT `created_at` FROM `{$account_updates_table}` WHERE `id` = ?", 2);
     $this->assertInstanceOf(DateTimeValue::class, $second_update_timestamp);
     $this->assertEquals('2016-02-22 13:13:13', $second_update_timestamp->format('Y-m-d H:i:s'));
     /* @var DateTimeValue $first_update_timestamp */
     $third_update_timestamp = $this->connection->executeFirstCell("SELECT `created_at` FROM `{$account_updates_table}` WHERE `id` = ?", 3);
     $this->assertInstanceOf(DateTimeValue::class, $third_update_timestamp);
     $this->assertEquals('2016-03-12 14:14:14', $third_update_timestamp->format('Y-m-d H:i:s'));
 }
コード例 #7
0
 /**
  * Test accounts canceled today, without going back through history.
  */
 public function testCountCanceledToday()
 {
     $this->insight->accounts->addTrial(1, new DateTimeValue('2016-02-12'));
     $this->insight->accounts->addTrial(2, new DateTimeValue('2016-02-13'));
     $this->insight->accounts->addTrial(3, new DateTimeValue('2016-02-14'));
     $this->insight->accounts->cancel(1, AccountsInterface::USER_CANCELED, new DateTimeValue('2016-02-16'));
     $this->insight->accounts->cancel(3, AccountsInterface::USER_CANCELED, new DateTimeValue('2016-02-16'));
     $this->current_timestamp = new DateTimeValue('2016-02-16');
     DateTimeValue::setTestNow($this->current_timestamp);
     $this->assertEquals(2, $this->insight->accounts->countCanceled());
 }
コード例 #8
0
ファイル: NowTest.php プロジェクト: activecollab/datevalue
 /**
  * Test if now can be overriden, for test purposes.
  */
 public function testTestNow()
 {
     DateTimeValue::setTestNow(new DateTimeValue('2013-10-02 11:18:32'));
     $this->assertEquals((new DateTimeValue())->format('Y-m-d H:i:s'), date('2013-10-02 11:18:32'));
 }
コード例 #9
0
ファイル: TestCase.php プロジェクト: activecollab/insight
 /**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     DateTimeValue::setTestNow(null);
     $this->current_timestamp = null;
     parent::tearDown();
 }
コード例 #10
0
ファイル: TestCase.php プロジェクト: activecollab/bootstrap
 /**
  * @param DateTimeValueInterface|null $now
  */
 public function setNow(DateTimeValueInterface $now = null)
 {
     $this->now = $now;
     DateTimeValue::setTestNow($this->now);
 }
コード例 #11
0
 /**
  * Tear down test environment.
  */
 public function tearDown()
 {
     DateTimeValue::setTestNow(null);
     parent::tearDown();
 }