Skip to content

Commit

Permalink
Merge pull request #39 from humhub-contrib/enh/php-cs-fixer
Browse files Browse the repository at this point in the history
Use PHP CS Fixer
  • Loading branch information
luke- authored Oct 3, 2024
2 parents 6c831bd + 6b2d12e commit fddee95
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 71 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: PHP CS Fixer

on: push

jobs:
fixers:
uses: humhub/actions/.github/workflows/module-php-cs-fixer.yml@main
1 change: 0 additions & 1 deletion Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class Assets extends AssetBundle
{

public function init()
{
$this->sourcePath = dirname(__FILE__) . '/assets';
Expand Down
8 changes: 3 additions & 5 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* BirthdayModule is responsible for the the birthday functions.
*
*
* @author Sebastian Stumpf
*/
class Module extends \humhub\components\Module
Expand All @@ -23,7 +23,7 @@ class Module extends \humhub\components\Module
* @var int the sort order for the birthdays sidebar widget
*/
public $sidebarSortOrder = 200;

/**
* On build of the dashboard sidebar widget, add the birthday widget if module is enabled.
*
Expand All @@ -34,7 +34,7 @@ public static function onSidebarInit($event)
if (Yii::$app->user->isGuest) {
return;
}

$module = Yii::$app->getModule('birthday');
$event->sender->addWidget(BirthdaySidebarWidget::class, [], ['sortOrder' => $module->sidebarSortOrder]);
}
Expand All @@ -57,5 +57,3 @@ public function enable()
}

}

?>
3 changes: 1 addition & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
'class' => 'humhub\modules\birthday\Module',
'namespace' => 'humhub\modules\birthday',
'events' => [
array('class' => Sidebar::class, 'event' => Sidebar::EVENT_INIT, 'callback' => array('humhub\modules\birthday\Module', 'onSidebarInit')),
['class' => Sidebar::class, 'event' => Sidebar::EVENT_INIT, 'callback' => ['humhub\modules\birthday\Module', 'onSidebarInit']],
],
];
?>
5 changes: 1 addition & 4 deletions controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
class ConfigController extends \humhub\modules\admin\components\Controller
{

/**
* Configuration Action for Super Admins
*/
Expand All @@ -28,9 +27,7 @@ public function actionIndex()
return $this->redirect(['/birthday/config']);
}

return $this->render('index', array('model' => $form));
return $this->render('index', ['model' => $form]);
}

}

?>
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
-----------------------
- Enh #36: Tests for `next` version
- Fix #37: Set module resources path
- Enh #39: Use PHP CS Fixer

1.0.15 - April 14, 2022
-----------------------
Expand Down
15 changes: 7 additions & 8 deletions models/BirthdayConfigureForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
class BirthdayConfigureForm extends \yii\base\Model
{

public $shownDays;
public $excludedGroup;

Expand All @@ -21,11 +20,11 @@ class BirthdayConfigureForm extends \yii\base\Model
*/
public function rules()
{
return array(
array('shownDays', 'required'),
array('shownDays', 'integer', 'min' => 0, 'max' => 90),
array('excludedGroup', 'integer', 'min' => 1, 'max' => 1000000),
);
return [
['shownDays', 'required'],
['shownDays', 'integer', 'min' => 0, 'max' => 90],
['excludedGroup', 'integer', 'min' => 1, 'max' => 1000000],
];
}

/**
Expand All @@ -35,10 +34,10 @@ public function rules()
*/
public function attributeLabels()
{
return array(
return [
'shownDays' => Yii::t('BirthdayModule.base', 'The number of days future birthdays will be shown within.'),
'excludedGroup' => Yii::t('BirthdayModule.base', 'The group id of the group that should be exluded.'),
);
];
}

}
7 changes: 4 additions & 3 deletions tests/codeception/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace birthday;

/**
Expand All @@ -20,7 +21,7 @@ class AcceptanceTester extends \AcceptanceTester
{
use _generated\AcceptanceTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
13 changes: 6 additions & 7 deletions tests/codeception/_support/BirthdayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
*/
class BirthdayHelper extends Module
{

public function seeTermsbox()
{
$this->assertTrue(Yii::$app->getModule('termsbox')->showTermsbox());
}

public function dontSeeTermsbox()
{
$this->assertFalse(Yii::$app->getModule('termsbox')->showTermsbox());
}

public function acceptTermsbox()
{
$this->getModule('Yii2')->sendAjaxPostRequest('index-test.php?r=/termsbox/index/accept');
$this->getModule('Yii2')->sendAjaxPostRequest('index-test.php?r=/termsbox/index/accept');
}

public function declineTermsbox()
{
$this->getModule('Yii2')->amOnPage(['/termsbox/index/decline']);
{
$this->getModule('Yii2')->amOnPage(['/termsbox/index/decline']);
}
}
9 changes: 5 additions & 4 deletions tests/codeception/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace birthday;

/**
Expand All @@ -19,8 +20,8 @@
class FunctionalTester extends \FunctionalTester
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/

/**
* Define custom actions here
*/
}
7 changes: 4 additions & 3 deletions tests/codeception/_support/UnitTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace birthday;

/**
Expand All @@ -20,7 +21,7 @@ class UnitTester extends \UnitTester
{
use _generated\UnitTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
9 changes: 4 additions & 5 deletions tests/codeception/acceptance/BirthdayCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@

class BirthdayCest
{

public function _before()
{
$this->module = Yii::$app->getModule('birthday');
Yii::$app->cache->flush();
$this->module->settings->set('shownDays', 2);
}

public function testBirthdayWidget(AcceptanceTester $I)
{
$I->wantToTest('if the birthday widget works as expected');
$I->amGoingTo('save the termsbox form without activation');

$I->amUser();
AccountSettingsPage::openBy($I);

$birthday = (new \DateTime())->sub(new \DateInterval('P29Y'))->format('Y-m-d');
$I->fillField('Profile[birthday]', Yii::$app->formatter->asDate($birthday));
$I->pressKey('#profile-birthday',WebDriverKeys::ENTER);
$I->pressKey('#profile-birthday', WebDriverKeys::ENTER);
$I->wait(1);
$I->click('Save profile');
$I->wait(2);

$I->amGoingTo('check my birthday widget on the dashboard');
DashboardPage::openBy($I);
$I->expectTo('see myself in the birthday widget');
Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/acceptance/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
*/
require(Yii::getAlias('@humhubTests/codeception/acceptance/_bootstrap.php'));
require(Yii::getAlias('@humhubTests/codeception/acceptance/_bootstrap.php'));
2 changes: 1 addition & 1 deletion tests/codeception/config/unit.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

return \tests\codeception\_support\HumHubTestConfiguration::getSuiteConfig('unit');
return \tests\codeception\_support\HumHubTestConfiguration::getSuiteConfig('unit');
26 changes: 13 additions & 13 deletions tests/codeception/functional/BirthdayCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ public function _before()
public function testBirthdayWidget(FunctionalTester $I)
{
$p1 = Profile::findOne(['user_id' => 1]);
$p1->birthday = '1987-'.date('m-d');
$p1->birthday = '1987-' . date('m-d');
$p1->save();

$p2 = Profile::findOne(['user_id' => 2]);
$p2->birthday = '1987-'.date('m-d', time() + 86400);
$p2->birthday = '1987-' . date('m-d', time() + 86400);
$p2->save();

$p3 = Profile::findOne(['user_id' => 3]);
$p3->birthday = '1987-'.date('m-d', time() - 86400);
$p3->birthday = '1987-' . date('m-d', time() - 86400);
$p3->save();

$I->wantToTest('if the birthday widget works as expected');
$I->amGoingTo('save the termsbox form without activation');

Expand All @@ -64,20 +64,20 @@ public function testBirthdayWidget(FunctionalTester $I)
public function testBirthdayWidgetWithLeapYear(FunctionalTester $I)
{
$p1 = Profile::findOne(['user_id' => 1]);
$p1->birthday = '1988-'.date('m-d');
$p1->birthday = '1988-' . date('m-d');
$p1->save();

$p2 = Profile::findOne(['user_id' => 2]);
$p2->birthday = '1988-'.date('m-d', time() + 86400);
$p2->birthday = '1988-' . date('m-d', time() + 86400);
$p2->save();

$p3 = Profile::findOne(['user_id' => 3]);
$p3->birthday = '1988-'.date('m-d', time() - 86400);
$p3->birthday = '1988-' . date('m-d', time() - 86400);
$p3->save();

$I->wantToTest('if the birthday widget works with leap years');
$I->amGoingTo('save the termsbox form without activation');

$I->amUser3();
$I->amGoingTo('check my birthday widget on the dashboard');
DashboardPage::openBy($I);
Expand Down
2 changes: 1 addition & 1 deletion tests/codeception/functional/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
*/
require(Yii::getAlias('@humhubTests/codeception/functional/_bootstrap.php'));
require(Yii::getAlias('@humhubTests/codeception/functional/_bootstrap.php'));
2 changes: 1 addition & 1 deletion tests/codeception/unit/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
* Initialize the HumHub Application for functional testing. The default application configuration for this suite can be overwritten
* in @tests/config/functional.php
*/
require(Yii::getAlias('@humhubTests/codeception/unit/_bootstrap.php'));
require(Yii::getAlias('@humhubTests/codeception/unit/_bootstrap.php'));
2 changes: 1 addition & 1 deletion tests/config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
'params' => [
#'moduleAutoloadPaths' => ['...'],
#'allowedLanguages' => ['en']
]
],
];
5 changes: 1 addition & 4 deletions tests/config/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@
return [
#'humhub_root' => '...',
'modules' => ['birthday'],
'fixtures' => ['default']
'fixtures' => ['default'],
];



11 changes: 4 additions & 7 deletions widgets/BirthdaySidebarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
class BirthdaySidebarWidget extends \yii\base\Widget
{

public function run()
{
$range = (int) Setting::Get('shownDays', 'birthday');
Expand All @@ -42,10 +41,10 @@ public function run()
return;
}

return $this->render('birthdayPanel', array(
'users' => $users,
'dayRange' => $range
));
return $this->render('birthdayPanel', [
'users' => $users,
'dayRange' => $range,
]);
}

public function getDays($user)
Expand Down Expand Up @@ -79,5 +78,3 @@ public function getAge($user)
}

}

?>

0 comments on commit fddee95

Please sign in to comment.