"PHP" / Говнокод #23992 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
class UserFixture extends ActiveFixture
{
    public function getDataMorozov() {
        return $this->getData();
    }

    protected function getData() {
...

Yii 2 fixtures. Называем костыли правильно

Запостил: kissarat kissarat, (Updated )

Комментарии (11) RSS

        • <?php
          
          namespace app\console\migrations;
          
          use app\models\Token;
          use app\models\Transfer;
          use app\models\User;
          use app\tests\fixtures\MorozovFixture;
          use yii\db\Schema;
          
          /**
           * Class m180325_045240_initial
           */
          class m180325_045240_initial extends Migration
          {
              public function safeUp() {
                  $this->createEnum('user_type', User::TYPES);
                  $this->createTimestampTable('user', [
                      'id' => Schema::TYPE_PK,
                      'nick' => $this->string(24)->notNull(),
                      'email' => $this->string(48)->notNull(),
                      'type' => "user_type not null default 'new'::user_type",
                      'parent' => $this->integer(),
                      'secret' => $this->string(60),
                      'admin' => $this->boolean()->notNull()->defaultValue(false),
                      'surname' => $this->string(48),
                      'forename' => $this->string(48),
                      'avatar' => $this->string(48),
                      'phone' => $this->string(32),
                      'telegram' => $this->string(32),
                      'skype' => $this->string(32),
                      'facebook' => $this->string(80),
                      'vk' => $this->string(80),
                      'site' => $this->string(160),
                  ]);
                  $this->addUserForeignKey('user', 'parent');
                  foreach (MorozovFixture::getDataMorozov('User') as $user) {
                      $this->insert('user', $user);
                  }
          Ответить
    • Кстати это мой код. Я решил не заморачиватся над загрузкой данных в миграциях и сделал
      <?php
      
      namespace app\tests\fixtures;
      
      
      use yii\test\ActiveFixture;
      
      abstract class MorozovFixture extends ActiveFixture
      {
          public static function getDataMorozov(string $class) {
              $class = 'app\tests\fixtures\\' . $class . 'Fixture';
              /**
               * @var MorozovFixture $fixture
               */
              $fixture = new $class();
              return $fixture->getData();
          }
      }
      Ответить

Добавить комментарий

Переведи на "PHP", guest!

    А не использовать ли нам bbcode?


    8