Skip to content

Commit

Permalink
Update PHPUnit tests based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lschaefer-sugarcrm committed Apr 2, 2018
1 parent 7f9c771 commit 639f28b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
22 changes: 16 additions & 6 deletions package/src/custom/Extension/modules/Schedulers/Ext/ScheduledTasks/StudentGradebookJob.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use Sugarcrm\Sugarcrm\custom\gradebook_fake\RecordManager;

class StudentGradebookJob implements RunnableSchedulerJob {
class StudentGradebookJob implements RunnableSchedulerJob
{

/**
* @var SchedulersJob
Expand All @@ -18,16 +19,15 @@ public function setJob(SchedulersJob $job)

/**
* This function defines the job that adds a new student to the GradebookFake app
* @param $job Information about the job. $job->data should be the id for the new Student (contact) record
* @param string $data The id for the new Student (contact) record
* @return bool true if a record was successfully created in the GradebookFake app
*/
public function run($data)
{
if (!empty($data))
{
if (!empty($data)) {
$bean = $this->getContactBean($data);

try{
try {
//Call the external GradebookFake app to create a new record in it
$rm = $this->getRecordManager();
$success = $rm->createStudentRecord($bean->email1, $bean->first_name, $bean->last_name);
Expand All @@ -50,10 +50,20 @@ public function run($data)
return false;
}

protected function getContactBean($id){
/**
* Get the Contact (Student) bean for the given id
* @param $id The id for which you want to retrieve a Contact (Student) bean
* @return null|SugarBean
*/
protected function getContactBean($id)
{
return BeanFactory::getBean('Contacts', $id);
}

/**
* Get the Record Manager for the GradebookFake app
* @return RecordManager The Record Manager for the GradebookFake app
*/
protected function getRecordManager()
{
return new RecordManager();
Expand Down
4 changes: 2 additions & 2 deletions package/src/custom/tests/School/unit-php/modules/Contacts/Student_GradebookTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,17 @@ public function testAddStudentToGradebook_CreatesTheJob()
*/
public function testAddStudentToGradebook_DoesNotCreateTheJob_NotAfterSaveEvent()
{
$this->sg->addStudentToGradebook($this->student, 'after_relationship_add', ['isUpdate' => false]);
$this->queue->expects($this->never())->method('submitJob');
$this->sg->addStudentToGradebook($this->student, 'after_relationship_add', ['isUpdate' => false]);
}

/**
* @covers ::addStudentToGradebook
*/
public function testAddStudentToGradebook_DoesNotCreateTheJob_IsUpdateEvent()
{
$this->sg->addStudentToGradebook($this->student, 'after_save', ['isUpdate' => true]);
$this->queue->expects($this->never())->method('submitJob');
$this->sg->addStudentToGradebook($this->student, 'after_save', ['isUpdate' => true]);
}

}
8 changes: 1 addition & 7 deletions package/src/custom/tests/School/unit-php/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@
<testsuites>
<testsuite name="all">
<directory>./</directory>
<directory>modules/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="false">
<directory suffix=".php">../../data/</directory>
<directory suffix=".php">../../src/</directory>
<directory suffix=".php">../../include/</directory>
<directory suffix=".php">../../clients/</directory>
<directory suffix=".php">../../modules/</directory>
<directory suffix=".php">../../api/</directory>
<directory suffix=".php">../../</directory>
</whitelist>
</filter>
<listeners>
Expand Down
4 changes: 2 additions & 2 deletions scripts/RunProfMPHPUnitTests.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# This script runs the Sugar PHPUnit tests. It assumes the Sugar Docker stack has already been started and that
# SetupSugarPHPUnit tests has completed successfully.
# This script runs the PHPUnit tests for the Professor M Module Loadable Package. It assumes the Sugar Docker stack has
# already been started and that SetupSugarPHPUnit tests has completed successfully.


######################################################################
Expand Down

0 comments on commit 639f28b

Please sign in to comment.